4

我们有一个使用 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: 之后的双斜杠匹配,因此 : 上的负匹配。

编辑:为澄清起见,我想查找所有帖子(wordpress 帖子/页面的正文),其 url 硬编码到具有双斜杠的页面中,但在 http: 之后的双斜杠不匹配。

正则表达式应匹配以下内容: 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/

4

2 回答 2

3

也许这样的事情会奏效。

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-29T20:01:38.977 回答
0

你可以使用:

regexp '(https?:\/\/|www\.)[^ ]*\/\/'

如果帖子包含http[s]://www.后跟包含其中的非空格字符,这将匹配帖子//

请参阅此SQLFiddle(改编自 sgeddes 的小提琴)。

或者您可以将您的正则表达式缩减为'[^:]\/\/'并查找包含该内容的帖子。

于 2013-01-29T20:20:06.523 回答