0

I'm trying to use Regexp_substr to extract the unit no from the Property Field. Below is the query.

regexp_substr(PROPERTY,'(#)[^\S]+ ')

While some of the results are correct, but others came back like below:

#05-08 DOVER PARKVIEW

May I know what do I need to do to omit all the alphabets or wordings? Thank you.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Adrian Tan
  • 33
  • 8

1 Answers1

1

The [^\S] pattern matches any char but a \ and a capital letter S.

You need to capture 1+ digits followed with - and again 1+ digits after a # and extract that part of the match only with

regexp_substr(PROPERTY, '#(\d+-\d+)', 1, 1, NULL, 1)

The last 1 argument tells the regex engine to extract the contents of the capturing group with ID 1 (it is the only capturing group in the pattern anyway).

  • # - a literal #
  • (\d+-\d+) - Capturing group 1 matching:
    • \d+ - 1 or more digits
    • - - a hyphen
    • \d+ - 1 or more digits.

See the online demo:

select regexp_substr('#05-08 DOVER PARKVIEW', '#(\d+-\d+)', 1, 1, NULL, 1) as RESULT from dual

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563