I'm trying to extract a value using regex. This value can be quoted or not:
For example:
foo: "bar"
or
foo: 'bar'
or
foo: bar
How can I extract only bar value?
Here is the regex I use:
^(foo):\s+(.*)--> works well to extractbarfromfoo: bar(https://regex101.com/r/cyZiId/1)^(foo):\s+'(.*)'--> works well to extractbarfromfoo: 'bar'(https://regex101.com/r/tjbVRq/1)^(foo):\s+"(.*)"--> works well to extractbarfromfoo: "bar"(https://regex101.com/r/kLnf6m/1)
How can I combine all three?
I don't want to use the first regex because it matches also the quotes "bar" and I only want to keep the string without the quotes.
Note that I would like to conserve the groups
This regex would solve your specific use case:
^(foo):\s+['"]*([^'"]*)https://regex101.com/r/XJkzOj/1If you give me more context about what you're trying to do I might be able to help more.
Good luck!