2

I have such a column:

{"abcVersion" : "1.2.3.4", https://klmno.com:5678/def", "xyzVersion" : "6.7.8.9"}

I now would like to get the numbers and . after the pattern xyzVersion" : " in order to get 6.7.8.9 as result. I tried this:

REGEXP_SUBSTR(column, '\d+[^a-z"]+') as result

Which obviously gives back 1.2.3.4. I do not want to specify the position with the arguments within the brackets but want to get the result specifically after the pattern mentioned above.

How could I do this?

6
  • is that a string or json? Commented Oct 7, 2021 at 6:58
  • Datatype is CLOB. Commented Oct 7, 2021 at 6:59
  • Maybe REGEXP_SUBSTR(col, '([0-9.]+)"}$', 1, 1, NULL, 1) will be enough? Commented Oct 7, 2021 at 7:05
  • 1
    Or, REGEXP_SUBSTR(col, '"xyzVersion" : "([^"]+)"', 1, 1, NULL, 1) as result? Commented Oct 7, 2021 at 7:07
  • The second one works out. Thanks a lot! Maybe you could also answer my question and maybe state what the arguments in your statement mean? :-) Commented Oct 7, 2021 at 7:14

2 Answers 2

1

You can use

REGEXP_SUBSTR(col, '"xyzVersion" : "([^"]+)"', 1, 1, NULL, 1) as result

Notes:

  • "xyzVersion" : "([^"]+)" matches "xyzVersion" : ", then captures one or more chars other than " into Group 1 and then matches a "
  • The last 1 argument tells REGEXP_SUBSTR to only return the capturing group 1 value (the first 1 is the position to start searching from and the second 1 tells to match the first occurrence).
Sign up to request clarification or add additional context in comments.

Comments

0

One option would be using REGEXP_REPLACE()(TO_CHAR() conversion might be added in order to convert CLOB to an ordinary string) such as

SELECT TO_CHAR(REGEXP_REPLACE(col,'(.*xyzVersion" : )"(.*)("})','\2')) AS result
  FROM t     

RESULT
-------
6.7.8.9

Demo

2 Comments

Thanks, but in my case this one did not work out but extracted the whole string in my column...
you're welcome @Tobitor , can you share the case for which the expression doesn't work properly ..?

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.