我们有一个使用 wordpress 的网站,我们发现在某些时候,一个错误的插件或用户错误在 siteurl 之后添加了双斜杠(例如,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: 之后的双斜杠匹配,因此在 : 上进行负匹配。
编辑:为了澄清起见,我想找到所有将 url 硬编码到具有双斜杠的页面但不匹配 http 之后的双斜杠的帖子(wordpress 帖子/页面的正文) :.
正则表达式应匹配以下内容:
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/
最佳答案
也许这样的事情会奏效。
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 .
祝你好运。
关于php - 用于查找正文中带有双斜杠的内部 URL 的 MySQL 正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14591023/