0

I want to match the following URL

/root/folder/123

without the /root in front of it. I was trying around with this pattern ((?!root).)*$ which I found in this answer: https://stackoverflow.com/a/406408/237312

but it doesn't work either, because it still matches oot/folder/123. I thought about something like (?!(root)+.)*$ which matches nothing, so I'm looking for an answer here.

Community
  • 1
  • 1
sascha
  • 4,671
  • 3
  • 36
  • 54
  • Do you want to match the URL but return everything without `/root` or do you want to match URLs like this if they do **not** start wit `/root`? – Martin Ender Nov 05 '12 at 10:51
  • I want to match URLs starting with `/root`in front, but I don't want to match it. Kev's asnwer is exactly what I was looking for. – sascha Nov 05 '12 at 10:55

2 Answers2

2

You can use lookbehind syntax: (?<=...)

For example:

(?<=/root).*$

It'll match /folder/123.

kev
  • 155,172
  • 47
  • 273
  • 272
1

You could do this:

\/root(.+)

The first group, i.e., $1 will be /folder/123

Jiman
  • 185
  • 2
  • 13