2014-09-05 48 views

回答

1

RegexBuddy给出了关于第一这个警告 '?'

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

,如果你删除它,它似乎工作,即^(.+[^\/:])(?=[?\/]|$)

然而,如果你试图解析该正则表达式将无法工作的BaseURL。使用此代替:

select regexp_replace('....', '^(.*:)//([a-z\-.]+)(:[0-9]+)?(.*)$', '\2') 
+0

谢谢。你能链接正则表达式吗? – 1252748 2014-09-05 16:34:52

+0

'SELECT regexp_replace('http://stackoverflow.com/questions/1991608/find-base-name-in-url-in-javascript','^(。+ [^ \ /:])(?= [? \ /] | $)','\ 1')AS content_url;'给我一个盒子。就像一个小“未知字符”框。 – 1252748 2014-09-05 16:37:55

+0

@ thomas也许是逃避,在这里工作http://www.sqlfiddle.com/#!15/cfab1/4/0 – gordy 2014-09-05 16:48:21

0

PostGreSQL有一个有趣的正则表达式引擎。我花了一段时间才弄清楚什么是逃脱的,哪些需要双重逃脱。我的解决方案是:

(regexp_matches(content_url,'(https?:\/\/\\w+(?:\\.\\w+)+)'))[1] AS content_url 

希望这可以帮助某人。

相关问题