What would be a basic regular expression which finds some string if given the string quuz="bleh" foo="some string" bar="some other string" where some string and some other string are arbitrary strings.
views:
20answers:
2
+1
A:
foo="([^"]*)"
The first (and only) capture group will contain what was between the quotes. It assumes that the contents of the quotes might be empty, but definitely include no double-quote characters.
Jeremy W. Sherman
2010-10-22 19:57:18
+1
A:
Any string between quotes:
"([^"]*)"
Any string between quotes called foo:
foo="([^"]*)"
Any string between quotes, handling escaped quotes correctly, i. e. matching 2\" by 4\" in "2\" by 4\"":
"((?:\\.|[^"\\])*)"
In all cases, the overall match includes the surrounding quotes; the capturing group $1 will contain the string you're interested in. How to access that depends on your regex implementation.
Tim Pietzcker
2010-10-22 19:58:54