November 19th, 2012, 11:46 PM
Regex Replace Word Between 2 Characters
Hi guys I need help with this reg ex:
I want to search for every word between:
/ and _ and have everything between removed (except the backslash)
I tried this
But the problem is that if there is
/farm instead of /village/farm
I only want the removal to start from the last backslash not every back slash before it as well. So the correct result for the last example should be
I appreciate any help. Thanks
November 20th, 2012, 12:13 AM
What language are you using? If it's PCRE-compatible then
(?<=/) finds a slash and starts the expression immediately after while [^/_]+ matches a bunch of non-slash, non-underscore characters.
November 20th, 2012, 12:45 AM
Thanks for the response. I tried the code but it didn't work. I'm using Emeditor. I actually did it in a different way, thanks though
Originally Posted by requinix
November 20th, 2012, 04:09 AM
this is how I would do it in Perl:
or (using parens or semi-colon as separator rather than / to avoid escaping):
For example, if you have the following string: "/foo/bar_baz/", these regexes will return this: "/foo/baz/", which is what you want, as far as I understand.
I leave it to you to adapt to your specific regex package, which I do not know.