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:

xpath("/root/framework_root/framework_mg/controllers/controller/message-listener/@message/text()", "|")

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.

1. /root/framework_root/framework_mg/controllers/controller/message-listener/@message/text()
2. |

Any ideas?

(I SUCK at RegEx, and I am hoping someone can show me the light!)

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Tom Chiverton's Gravatar xpath\("([^"]*)", "([^"]*)

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*"([^"]*)"
# Posted By Tom Chiverton | 4/25/07 8:12 AM
Rob Wilkerson's Gravatar What Tom said, except don't forget the close parenthesis:

\("([^"]*)",\s*"([^"]*)"\)

Also, what about single quotes? Maybe something like this?

\((["'])([^'"]*)\1,\s*(['"])([^'"]*)\3"\)
# Posted By Rob Wilkerson | 4/25/07 12:13 PM
Tom Chiverton's Gravatar I didn't think the close ) was important.
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.
# Posted By Tom Chiverton | 4/25/07 1:04 PM
Felipe Pena's Gravatar In PHP:

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"
)
*/


;)
# Posted By Felipe Pena | 7/5/07 6:39 PM