Reputation: 11
Hi all i was hoping someone could help be with some basic regex i am really struggling with.
Bascially i need to match a url for redirection. I have been using
^~/abc(/)?
however i need to change the end part to just check the last optional character as this will also match ^/abcd
Upvotes: 1
Views: 2177
Reputation: 27486
How about ^~/abc(/?)
or more generally: ^~/[a-zA-Z0-9]+/?
Upvotes: 3
Reputation: 14459
Assuming PCRE, you will want:
^~/abc(.)?$
Which will match "~/abc" followed (optionally) by any single character, which will be captured. Leave the () off if you don't need to capture said character.
Just like ^
matches the beginning of string (or line, depending upon mode), $
matches the end of string (or line).
Upvotes: 1