1

hello i am trying to search ddw_0_op1 with mysql regex serach query

SELECT * FROM wp_postmeta WHERE meta_key RLIKE '(?=.*ddw_)(?=.*_op1)'

but in results its also displaying results from this field

_ddw_0_op1

but i want to display results only from this field ddw_0_op1 . how i can achieve that enter image description here in this picture i want results from http links field i hope that makes sense now

9
  • Well, .*ddw_ matches _ddw_. Not exactly sure what you're looking for... Commented Feb 1, 2018 at 19:58
  • 1
    You need to give better examples of things you do want to match and things that you don't. Do you literally only want to match "ddw_0_op1"? Commented Feb 1, 2018 at 20:00
  • 1
    Since when does mysql regex support lookarounds? Commented Feb 1, 2018 at 20:01
  • the 0 increases with numbers @ patrick Commented Feb 1, 2018 at 20:05
  • 2
    Why do you need regex? Try WHERE meta_key LIKE 'ddw_%_op1' or if you need to narrow the wildcard down to digits with regex WHERE meta_key RLIKE '^ddw_[[:digit:]]+_op1$' Commented Feb 1, 2018 at 20:15

1 Answer 1

1

With INDEX(meta_key), this may be faster:

WHERE meta_key LIKE   'ddw_%_op1'
  AND meta_key RLIKE '^ddw_[[:digit:]]+_op1$'

First the LIKE (without a leading wildcard) can use the index. Then the RLIKE will verify that only digits are in the middle (without using the index).

Since this smells like a WP schema, here are some more tips on wp_postmeta. (The tips won't speed up your ddw query, but may help others.)

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.