URGENT!: Seeking RegEx guru
April 25, 2007 ·
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!)
Tags: cfeclipse · coldfusion · webdev
4 responses
1 Tom Chiverton // Sep 22, 2008 at 4:11 PM
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*"([^"]*)"
2 Rob Wilkerson // Sep 22, 2008 at 4:11 PM
\("([^"]*)",\s*"([^"]*)"\)
Also, what about single quotes? Maybe something like this?
\((["'])([^'"]*)\1,\s*(['"])([^'"]*)\3"\)
3 Tom Chiverton // Sep 22, 2008 at 4:11 PM
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.
4 Felipe Pena // Sep 22, 2008 at 4:12 PM
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"
)
*/
;)