简体   繁体   English

MySQL正则表达式寻找链接

[英]Mysql regex looking for links

How to get this expression work: 如何使此表达式起作用:

SELECT post_content 
FROM wp_posts 
WHERE post_content REGEXP 'http:\/\/www.google.com\/\?link=.*_1'

I have some posts with some links in this style, so I wont get list of all posts with this links. 我有一些带有这种样式的链接的帖子,所以我不会获得所有带有此链接的帖子的列表。

With this query I get an empty list. 通过此查询,我得到一个空列表。

Table: 表:

| id | wp_posts | other fields....
| 1  | text <a href="http://www.google.de/?link=test_1">Link</a> text | ....

So I have to find the post ID 1 所以我必须找到帖子ID 1

Escaping / is not necessary, but you'll need to use \\\\ to escape your question mark . 不必转义/ ,但是您需要使用\\\\来避开问号

Note 注意
Because MySQL uses the C escape syntax in strings (for example, “\\n” to represent the newline character), you must double any “\\” that you use in your REGEXP strings. 由于MySQL在字符串中使用C转义语法(例如,“ \\ n”表示换行符),因此必须对REGEXP字符串中使用的任何“ \\”加倍。

Also, searching for google in the correct country is a good idea :-) 另外,在正确的国家/地区搜索google是一个好主意:-)

This'll work; 这会起作用;

SELECT post_content 
FROM wp_posts 
WHERE post_content REGEXP 'http://www.google.de/\\?link=.*_1';

An SQLfiddle to test with . 要使用进行测试的SQLfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM