I am trying to extract all words that start from ‘M’ character.
For example I have a string:
"[{"name": "Mary", "type": "Dog"}, {"name": "Max", "type": "Dog"}]"
I want to get: "Mary, Max"
I tried to regex_replace([{"name": "Mary", "type": "Dog"}, {"name": "Max", "type": "Dog"}], ‘W’, ”, ‘g’) and left only words, but don’t know the correct regex to extract all words starting with ‘M’. I also tried this: substring("name Mary type Dog name Max type Dog" from ‘w*Mw*’) but this gives me only one word.
2
Answers
You can use the following pattern.
Output for group 1.
You can use Postgresql’s regexp_matches function. Documentation here.
This query might help.
It returns a comma separated string. The ‘g’ flag specifies that all results must be returned.
One other way to get the same result is via LIKE operator.