我们有一个使用wordpress的网站,我们发现在某些情况下,一个糟糕的插件或用户错误会在网站etc后添加双斜杠(例如,http://example.site//category1/或http://example.site/category1//category2/等)。
这似乎是有效的,但似乎没有足够的结果。
SELECT id, post_content
FROM `wp_posts`
where post_content
regexp '(href="[^"]*[^:]\/\/[^"]*)'
and post_status in('draft','publish')
order by id asc有没有更好的方法来做这件事?我不希望它与http:后面的双斜杠匹配,因此在:上出现负匹配。
编辑:为了澄清,我想找到所有的帖子( wordpress帖子/页面的正文),这些帖子的url被硬编码到具有双斜杠的页面中,但与http:后面的双斜杠不匹配。
Regexp应该与以下内容匹配:http://example.site//category1/或http://example.site/category1//category2/,甚至http://example.site/category1/category2//或example.site/category1//category2/
但不应与以下内容匹配:http://example.site/category1/或http://example.site/category1/category2/
发布于 2013-01-30 04:01:39
也许像这样的东西能行得通。
SELECT *
FROM wp_posts
WHERE CASE WHEN instr(post_content,'http://') > 0 THEN
substring(post_content,7) regexp '\/\/'
ELSE
post_content regexp '\/\/'
END这是SQL Fiddle。
祝好运。
发布于 2013-01-30 04:20:07
您可以使用:
regexp '(https?:\/\/|www\.)[^ ]*\/\/'如果帖子包含http[s]://或www.,后跟带有//的非空格字符,则匹配该帖子。
请看这个SQLFiddle (改编自sgeddes的小提琴)。
或者,您可以将正则表达式减少为'[^:]\/\/',然后查找包含它的帖子。
https://stackoverflow.com/questions/14591023
复制相似问题