URGENT!: Seeking RegEx guru
Posted At : April 25, 2007 6:58 AM
| Posted By : Mark Drew
Related Categories:
coldfusion,
cfeclipse,
regex
No, not for a job, I just need to find a reg ex expression to find the values of the following expression:
basically its a function, you pass in two values, the xpath and then a delimiter. I need to get the value of the parameters. e.g.
2. |
Any ideas?
(I SUCK at RegEx, and I am hoping someone can show me the light!)



You don't say how the input could vary (is that space after the comma always there ? is it always lower case ?), so an alternative might be:
\("([^"]*)",\s*"([^"]*)"
\("([^"]*)",\s*"([^"]*)"\)
Also, what about single quotes? Maybe something like this?
\((["'])([^'"]*)\1,\s*(['"])([^'"]*)\3"\)
Also, we both forgot that people put spaces in funny places, which leaves us with:
xpath\s*\(\s*"([^"]*)"\s*,\s*"([^"]*)"
Mixing " and ' leads to problems (what it the first argument has a ' in but has " at both ends), something like ("|') might work better.
preg_match("/xpath\(\s*((?s:\"(?:(?!(?<!\\\)\").)+\"|'(?s:(?!(?<!\\\)').)+'))\s*,\s*((?s:\"(?s:(?!(?<!\\\)\").)+\"|'(?s:(?!(?<!\\\)').)+'))\s*\)/",
"xpath('blabla\'blabla\'bllaal', \"foo\")",
$m);
print_r($m);
/**
Array
(
[0] => xpath('blabla\'blabla\'bllaal', "foo")
[1] => 'blabla\'blabla\'bllaal'
[2] => "foo"
)
*/
;)