Jorge Ferrari
Jorge Ferrari

Reputation: 152

How to find rows with only special characters on a field using MySQL?

Here's the deal, i must find the rows, on which a determined field contains only special characters, I've been trying using regex, with no success.

Can someone help me please?

Upvotes: 2

Views: 3970

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627082

You can use

SELECT * FROM table WHERE col REGEXP '^[^[:alnum:][:space:]_]+$'

See the regex demo.

The regex pattern breakdown:

  • ^ - start of string
  • [^ - start of the negated character class that matches any character other than defined in this class
    • [:alnum:] - letters and digits
    • [:space:] - whitespace
    • _ - underscore
  • ] - end of the negated character class
  • + - the characters matched by the negated character class must be 1 or more occurrences
  • $ - end of string

Upvotes: 7

Related Questions