I'm trying to get a regex to capture the base URL from a URL string. This
^(.+?[^\/:])(?=[?\/]|$)
works. REGEX101
But when I try to use it within postgresql
regexp_replace(content_url,'^(.+?[^\\/:])(?=[?\\/]|$)', '\1')
it does not
I'm trying to get a regex to capture the base URL from a URL string. This
^(.+?[^\/:])(?=[?\/]|$)
works. REGEX101
But when I try to use it within postgresql
regexp_replace(content_url,'^(.+?[^\\/:])(?=[?\\/]|$)', '\1')
it does not
RegexBuddy gives this warning about the first '?'
PostgreSQL is inconsistent in the way it handles lazy quantifiers in regular expressions with alternation because it attempts to match the longest alternative, instead of being eager and accepting the first alternative that matches
and if you remove it, it seems to work, i.e ^(.+[^\/:])(?=[?\/]|$)
however, if you're trying to parse the baseurl that regex won't work. Use this instead:
select regexp_replace('....', '^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$', '\2')
SELECT regexp_replace('http://stackoverflow.com/questions/1991608/find-base-name-in-url-in-javascript','^(.+[^\/:])(?=[?\/]|$)', '\1') AS content_url; just gives me a box. Like a little "unknown character" box.[Error Code: 0, SQL State: 2201B] ERROR: invalid regular expression: invalid character range :(