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$)/
You cannot do this (directly) in JavaScript. JavaScript converts the object you are matching on to string, thus if you are matching on some var which is null, you will be matching on the string null. The regex cannot tell the difference between a null var and a var containing the string null. Note also that /(.{0}|^ADO$)/ will match any string as .{0} is the same as the empty expression which always matches. Your expression is equal to /(|^ADO$)/ which is almost the same as /(^ADO$)?/.
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';
null. The regex cannot tell the difference between a null var and a var containing the stringnull. Note also that/(.{0}|^ADO$)/will match any string as.{0}is the same as the empty expression which always matches. Your expression is equal to/(|^ADO$)/which is almost the same as/(^ADO$)?/.