Oracle SQL Regex not returning expected results

前端 未结 1 1506
被撕碎了的回忆
被撕碎了的回忆 2021-01-15 18:32

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

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

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

相关标签:
1条回答
  • 2021-01-15 19:16

    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 |
    
    0 讨论(0)
提交回复
热议问题