How do I write a regex that ignores strings starting with a particular prefix, and captures everythi
Posted
by Mark Rogers
on Stack Overflow
See other posts from Stack Overflow
or by Mark Rogers
Published on 2010-04-07T22:39:10Z
Indexed on
2010/04/07
22:43 UTC
Read the original article
Hit count: 181
regex
|url-rewriting
Background:
I'm trying to come up with a regex for a rewrite rule that will take anything that does not start with a particular prefix, and add that prefix to it. But urls that already have the prefix should be rejected by the regular expression (because they already have the url).
Example:
If the prefix is s1
a string like home
will capture the home
part. But a string like s1/home
, will not capture anything.
This way I can add the capture group onto the prefix, so that 'home' will become 's1/home'.
I've tried (^s1/)
, but I'm missing something here, because that rejected 'home' for some reason.
© Stack Overflow or respective owner