If you just want to change the base URI, you can try the BASE element :
<base href="/basepath/">
But note that changing the base URI affects all relative URIs, not just relative URI paths.
Otherwise, if you really want to use a regular expression, consider that the relative path, as you want, should be of type path-noscheme (see RFC 3986 ):
path-noscheme = segment-nz-nc *( "/" segment ) segment = *pchar segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) ; non-zero-length segment without any colon ":" pchar = unreserved / pct-encoded / sub-delims / ":" / "@" pct-encoded = "%" HEXDIG HEXDIG unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
So, the beginning of the URI should match:
^([a-zA-Z0-9-._~!$&'()*+,; =@ ]|%[0-9a-fA-F]{2})+($|/)
But please use the correct HTML parser for HTML parsing. You can then query the DOM to get the href attributes and check the value using the regular expression above.
Gumbo source share