1

I am trying to search for this pattern ab1234. I tried col like 'ab[0-9][0-9][0-9][0-9]' col like '(ab)[0-9]{4}' col like 'ab####' None of these are working. I checked this website https://www.w3schools.com/sql/sql_wildcards.asp, but it is not very helpful. Any advice is appreciated :)

leftjoin
  • 36,950
  • 8
  • 57
  • 116
Rachel Y
  • 13
  • 3

2 Answers2

1

Use rlike for regexp check:

col rlike 'ab\\d{4}' --containing ab and 4 digits in any place of the string

Or more strict pattern:

col rlike '^ab\\d{4}$' --Exactly ab and 4 digits, no other characters before or after
leftjoin
  • 36,950
  • 8
  • 57
  • 116
1
select * from table where col rlike 'ab[0-9]{4}'
Amardeep Flora
  • 1,255
  • 6
  • 13
  • 29
  • The community encourages adding explanations alongisde code, rather than purely code-based answers (see [here](https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers)). – costaparas Feb 08 '21 at 05:24