Mysql REGEXP how to make an exact match

I have a notes column that contains text and has an identifier inside the text, something like "some random text (actvityid - 1234)"

In this case, I need to output the identifier 1234 and update the activid column in the same table.

my request is as follows

"UPDATE table_name SET activityId = {$f['activityId']} WHERE notes REGEXP '{$f['activityId']}' "

the problem with this is that if $ f ['activityId'] is 34 or 123, for example, it still updates the activid column with that value. How can I make an exact match on "1234" and update only if it matches the entire line, here is "1234".

Many thanks.

+3
source share
2 answers
WHERE notes REGEXP CONCAT('(actvityid - ', {$f['activityId']}, ')')

or

WHERE notes REGEXP '[[:<:]]{$f['activityId']}[[:>:]]'

[[:<:]] [[:>:]] .

+5

CONCAT, PHP, REGEXP,

WHERE notes LIKE '%(actvityid - {$f['activityId']})%'
+1

Source: https://habr.com/ru/post/1751178/


All Articles