Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql Regex with NULL value

Tags:

regex

mysql

How can I match a field in the MySql-Database with a regular expression that should be null or a defined string? In Javascript the expression would look like this (and in JS it works) /(.{0}|^ADO$)/

like image 528
andred Avatar asked Sep 04 '26 13:09

andred


1 Answers

It might be clearest to use IFNULL so you can explictly indicate how you want to handle NULLs (I'm always looking for ways to make code easier to understand, rather than more tricksy). Perhaps something like this:

SELECT * from table where IFNULL(field, '') REGEXP 'whatever';
like image 134
D Mac Avatar answered Sep 07 '26 03:09

D Mac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!