Search code examples
c#regexurlrelative-path

Regular Expression to match relative URLs


Looking for a regular expression that match the following relative URLs:

All urls starts with /abc/ but we don't know where it ends and it doesn't have any file extension at the end.

/abc/xyz

/abc/part1/part2

/abc/red/blue/white/green/black

and so on.

Any help?


Solution

  • Try this regular expression:

    /abc/(?:[A-Za-z0-9-._~!$&'()*+,;=:@]|%[0-9a-fA-F]{2})*(?:/(?:[A-Za-z0-9-._~!$&'()*+,;=:@]|%[0-9a-fA-F]{2})*)*
    

    This is derived from the ABNF of a generic URI.