0

can you provide me with confirmation whether I correctly converted following SQL Queries into regex expression?

1) SQL:

CLASSIFICATION_CODE not like '24%'

REGEX:

CLASSIFICATION_CODE <> '([^2]|2[^4])'

2) SQL:

TYPE_CODE NOT LIKE 'DKRI%' OR TYPE_CODE  NOT LIKE 'KRI%' OR TYPE_CODE  <> '355' OR TYPE_CODE  <> '303'

REGEX:

TYPE_CODE <> '([^DK3]|D[^K]|DK[^R]|DKR[^I]|K[^R]|KR[^I]|3[^50]|30[^3]|35[^5]' 

Thanks in advance,

a.

4
  • Which language are you using to convert? Also, your regex patterns are incorrect: NOT LIKE 'DKRI%' would convert to ^DKRI and <> 355 would convert to ^355 Commented Mar 7, 2018 at 15:51
  • I am using Oracle's DB regex. Commented Mar 7, 2018 at 16:00
  • You're using Oracle DB regex to convert? Commented Mar 7, 2018 at 16:01
  • Well, to be precise - I do use SQL Extensions toolkit for Netezza which is pretty much the same as Oracle one. Commented Mar 7, 2018 at 16:12

1 Answer 1

1

No. Regular expressions match anywhere, but like is always the full string. So you need to anchor the regular expressions:

regexp_like(CLASSIFICATION_CODE, '^([^2]|2[^4])'

Although, I would write this as:

not regexp_like(CLASSIFICATION_CODE, '^24')

Your second is much simpler:

CLASSIFICATION_CODE IS NOT NULL

or:

regexp_like(CLASSIFICATION_CODE, '.')

I could speculate that you really intend AND between the conditions, but with OR, any string is going to match.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.