-1

I wanted to extract all the "name" values from this:

{"id":"1","name":"simpleword","type":"test"},{"id":"123","name":"f23ÜÜ","type":"prod"}

I was presented with the following solution;

regexp_substr_all(s, 'name":"([^"]*)"', 1, 1, '', 1)

and now I am trying to understand the regex. I understand that the

'name":"([^"]*)"'

part extracts the whole part:

"name":"simpleword",
"name":"f23ÜÜ"

but how is the 1, 1, '', 1 working to extract the values of the name keys only?

2
  • See REGEXP_SUBSTR_ALL reference. These are <position> [ , <occurrence> [ , <regex_parameters> [ , <group_num> ] args. Commented Sep 27, 2022 at 7:58
  • Yes, I have already seen the names, but how are they helping in extract the name values? How is the occurence and position working here? @WiktorStribiżew Commented Sep 27, 2022 at 8:10

1 Answer 1

1

how is the 1, 1, '', 1 working to extract the values of the name keys only?

They are all explained here: https://docs.snowflake.com/en/sql-reference/functions/regexp_substr_all.html#arguments

Yes, I have already seen the names, but how are they helping in extract the name values?

In your case, position and occurrence are default values, so they are just entered to be able to enter the rest of the parameters. I don't think regex_parameters is important but the group number (last 1) is required otherwise the regexp will not care about grouping (), and will return the whole matching string:

Sign up to request clarification or add additional context in comments.

2 Comments

makes sense. about "([^"]*)" this part, i understand that we group everything between the " " but why is there another " inside the square brackets?
It says any character but not ". So it takes the words between " characters.

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.