I want to retrieve all entries from a database that have three or more special characters next to each other using a regex. I'm assuming I use the REGEX_LIKE function and the code is something like:
SELECT * FROM <tablename> WHERE REGEXP_LIKE(<columnname>), '^(?!.*[&@£#$()''*,.:; -]{3})*$');
But I'm can't get the regex right. Anyone help please?
CodePudding user response:
Drop the ^
and $
anchors, and just search for the 3 special characters:
SELECT * FROM <tablename> WHERE NOT REGEXP_LIKE(col, '[&@£#$()''*,.:; -]{3}');
CodePudding user response:
You can save yourself a bunch of writing by using the [:punct:]
character class:
SELECT *
FROM your_table yt
WHERE REGEXP_LIKE(yt.your_col, '[[:punct:]]{3}');