user2510809
user2510809

Reputation: 245

Using RegExp in sql to find rows that only contain 'x'

How do i use a regexp to only find rows where the first name only includes one type of character 'x' but it doesnt matter how many characters there are.

So far I came up with:

 REGEXP_LIKE(LOWER(fst_name),'^x+$'))

possible rows I am looking for:

'x'

'xx'

'xxx'

'xxxxxxxxx'

So im interpreting this as meaning find the rows where x is at the beginning and the end of the field and there can be only x's inbetween. Am I interpreting this correctly?

or is it possible to have: 'xxxxxxaxxxxx'

Upvotes: 0

Views: 87

Answers (1)

Palpatim
Palpatim

Reputation: 9272

Your regex is correct:

^x+$
  • ^ is the "start" anchor
  • x is the character for which you are searching. I assume it isn't a regex metacharacter
  • + is the "one or more" quantifier
  • $ is the "end" anchor

So I would interpret your regex to match all of the cases you supplied, and would not match something like 'xxxxaxxxx'. http://regex101.com/r/dE8vU6

It's been long enough since I used Oracle that I don't recall whether your REGEX_LIKE syntax is correct there, but it seems right to me.

Upvotes: 1

Related Questions