2

I'm testing oracle REGEXP_SUBSTR function and regexp that works in Python or Web testing tools like https://regex101.com/ doesn't work with Oracle.

Example:

((?:NF\s{0,1}EN){0,1}[\s]{0,1}ISO[\s]{0,1}[\d]{3,6}(?:[\:]{0,1}\d{1,4}){0,1}[\-]{0,1}\d{0,1})

STRING: VAS H M1582/950-80 ABCDFEF - ISO4014

MATCH: ISO4014, but oracle regexp_like doesn't match:

NOT MATCH:

SELECT REGEXP_SUBSTR (
          'VAS H M1582/950-80 ABCDFEF - ISO4014',
          '((?:NF\s{0,1}EN){0,1}[\s]{0,1}ISO[\s]{0,1}[\d]{3,6}(?:[\:]{0,1}\d{1,4}){0,1}[\-]{0,1}\d{0,1})')
  FROM DUAL;

Any idea?

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    Oracle doesn't support all flavours of regular expression syntax; [see the documentation](https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/Oracle-Regular-Expression-Support.html#GUID-969230D6-FC1A-4C75-BF2A-6B1BE909DED6). – Alex Poole Jun 30 '21 at 13:01

2 Answers2

1

You can use

(NF\s?EN)?\s?ISO\s?\d{3,6}(:?\d{1,4})?-?\d?

See its demo at regex101.com.

Note:

  • Oracle regex does not "like" [\s], i.e. shorthand character classes inside brackets, you should not use them like that
  • {0,1} is equal to ? (one or zero occurrences)
  • (?:...), non-capturing groups, are not supported, you should replace them with capturing groups. (Note that (:? is not a non-capturing group, it is just an optional colon at the start of the second capturing group in the pattern).
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
0

You can use my XT_REGEXP for PCRE compatible regular expressions: https://github.com/xtender/XT_REGEXP

select * 
from
 table(xt_regexp.get_matches(
  'VAS H M1582/950-80 ABCDFEF - ISO4014',
  '((?:NF\s{0,1}EN){0,1}[\s]{0,1}ISO[\s]{0,1}[\d]{3,6}(?:[\:]{0,1}\d{1,4}){0,1}[\-]{0,1}\d{0,1})'
));

Results:

COLUMN_VALUE
------------------------------
 ISO4014

1 row selected.
Sayan Malakshinov
  • 8,492
  • 1
  • 19
  • 27