tags:

views:

35

answers:

3

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

A: 

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).

Chris
A: 

How about ^~/abc(/?)

or more generally: ^~/[a-zA-Z0-9]+/?

FrustratedWithFormsDesigner
A: 

I'll do something like this : ^~/([a-zA-Z0-9]+/?)*$

hoang