0

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

2
  • can you show table contents? and what output required? Commented Apr 6, 2013 at 9:46
  • @thumbernirmal I added a little example. Commented Apr 6, 2013 at 10:10

1 Answer 1

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.

Also, searching for google in the correct country is a good idea :-)

This'll work;

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

An SQLfiddle to test with.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.