Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to match alphanumeric -- query rows that contain numbers in postgresql

I want to write a regex that matches string that has both numeric and alphabets. ^[a-zA-Z0-9]*$ -- this pattern returns numeric as well as alphabets, but I want only alphanumeric. Basically I'm using postgresql to query rows that contain numericals in it.

like image 640
Mike Avatar asked Sep 08 '25 18:09

Mike


1 Answers

I think multiple regex's is the easiest way:

where col ~ '^[a-zA-Z0-9]*' and
      col ~ '[0-9]' and
      col ~ '[a-zA-Z]'

There is probably a complicated regexp that combines this all together, but this seems like the most intuitive method.

like image 50
Gordon Linoff Avatar answered Sep 10 '25 07:09

Gordon Linoff