0

I am using a regex that works perfectly in Java/PHP/regex testers.

\d(?:[()\s#-]*\d){3,}

Examples: https://regex101.com/r/oH6jV0/1

However, trying to use the same regex in Oracle SQL is returning no results. Take for example:

select *
from
(select column_value str from table(sys.dbms_debug_vc2coll('123','1234','12345','12 135', '1', '12 3')))
where regexp_like(str, '\d(?:[()\s#-]*\d){3,}');

This returns no rows. Why does this act so differently? I even used a regex tester that does POSIX ERE, but that still works.

0

1 Answer 1

3

Oracle does not support non-capturing groups (?:). You will need to use a capturing group instead.

It also doesn't like the perl-style whitespace meta-character \s match inside a character class [] (it will match the characters \ and s instead of whitespace). You will need to use the POSIX expression [:space:] instead.

SQL Fiddle

Oracle 11g R2 Schema Setup:

Query 1:

select *
from (
  select column_value str
  from   table(sys.dbms_debug_vc2coll('123','1234','12345','12 135', '1', '12 3'))
)
where regexp_like(str, '\d([()[:space:]#-]*\d){3,}')

Results:

|    STR |
|--------|
|   1234 |
|  12345 |
| 12 135 |
Sign up to request clarification or add additional context in comments.

2 Comments

Cool. This seems mostly right (for what it is), but it's not matching spaces e.g. '12 135'.
@Jeremy Updated - swap perl \s for POSIX [:space:] inside the character class (as others have already mentioned).

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.