shantanuo
shantanuo

Reputation: 32316

mysql regular expression

I found this query in mysql query log and I will like to know what exactly does it do.

select * from tblname WHERE TRIM(NAME) REGEXP 'John[      ]*Smith'

Upvotes: 0

Views: 100

Answers (1)

zerkms
zerkms

Reputation: 254926

It selects all rows from tblname where name (with spaces around removed, if any) equals to John<any number of spaces>Smith

So you'll find JohnSmith as well as John_________________________Smith (stackoverflow eats repetitive spaces, so I replaced them with underscore).

The regex itself is a little bloated and can be rewritten as John *Smith

Upvotes: 3

Related Questions