datalearner
datalearner

Reputation: 33

Oracle REGEXP_LIKE - search string not followed by specific character

I am looking to match string which is not followed by one character but can be followed by 0 or more of any other characters using REGEXP_LIKE in Oracle. For example, if I have these records:

ABCD
ABCDE
ABCDGH
ABCDF
ABCDUYR

I need to get all except ABCDE

I tried REGEXP_LIKE(column,'^ABCD[^E]') But this also omits ABCD. Please help.

Thanks!

Upvotes: 2

Views: 2438

Answers (2)

Vamsi Prabhala
Vamsi Prabhala

Reputation: 49260

To exclude strings that contain E followed by ABCD use

REGEXP_LIKE(col,'^ABCD([^E]|$)')

^ABCD([^E]|$) - ABCD followed by any character(s) other than E or the string ABCD and no other characters after that.

Upvotes: 1

C Quo
C Quo

Reputation: 27

Try this:

 REGEXP_LIKE(column,'^ABCD[^E]*')

* matches zeros or more characters

Upvotes: 1

Related Questions