goodEgg goodEgg -5 years ago 94
MySQL Question

MySQL REGEXP - Select certain pattern of numbers and characters

Anyone have a clue how I could go about trying to select a certain pattern of numbers with a

at the end?


SELECT pattern FROM table WHERE pattern REGEXP '1_2+2_2+3_2+4_2&2016-06-09&1';


SELECT pattern FROM table WHERE pattern REGEXP '2_1&2016-06-09&1';

using the same number-underscore-number, ampersand, date, ampersand, number; just as long as that number 1 is at the end?


Actually, let me phrase it better. How do I use
to select an ampersand and the number 1 at the end of a string?

Answer Source

You don't need regex. Just use LIKE:

LIKE '%&1'

The % makes it not be anchored to the start of the string. LIKE is not regex, but closer to a glob syntax. It may be faster than regex, too.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download