DrAske
asked on
Regular Expression - URGENT
Hi Experts ..
I want a regular exprssion that parse the following string
/package[@name='mypackage' ]/class[@n ame='mycla ss']/metho d[@name='s omething' and param[1]/typevaluespec='in t']
I want the first regular expression to return:
package[@name='mypackage']
class[@name='myclass']
method[@name='something' and param[1]/typevaluespec='in t']
I cannot split the string using '/' character since (3) contain '/' character.
this is URGENT!! please help.
I want a regular exprssion that parse the following string
/package[@name='mypackage'
I want the first regular expression to return:
package[@name='mypackage']
class[@name='myclass']
method[@name='something' and param[1]/typevaluespec='in
I cannot split the string using '/' character since (3) contain '/' character.
this is URGENT!! please help.
ASKER
ooh!! I am sooo sorry, you got me wrong!!
/package[@name='mypackage' ]/class[@n ame='mycla ss']/metho d[@name='s omething' and param[1]/typevaluespec='in t']
package, class , method are just an example!! you can say that the string between '/' and '[' character
must be [a-z]+.
My apologies,
/package[@name='mypackage'
package, class , method are just an example!! you can say that the string between '/' and '[' character
must be [a-z]+.
My apologies,
string testString = "/package[@name='mypackage ']/class[@ name='mycl ass']/meth od" +
"[@name='something' and param[1]/typevaluespec='in t']";
Regex packageRegex = new Regex("/.[^\\]]+");//
textBox1.Text = "";
foreach (Match m in packageRegex.Matches(testS tring))
textBox1.Text += m.Value + "]" + " ;$; ";
the regex "/.[^\\]]+" will get you all string between / and ] (it will exclude the ] so you will have to put it to the string after.
"[@name='something' and param[1]/typevaluespec='in
Regex packageRegex = new Regex("/.[^\\]]+");//
textBox1.Text = "";
foreach (Match m in packageRegex.Matches(testS
textBox1.Text += m.Value + "]" + " ;$; ";
the regex "/.[^\\]]+" will get you all string between / and ] (it will exclude the ] so you will have to put it to the string after.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thank you.
Thanks for the question and the points.
$string = <<<EOF
/package[@name='mypackage'
EOF;
$pattern = '@(/package.*?)(/class.*?)
preg_match_all($pattern, $string, $array);
echo '<pre>', print_r($array, true), '</pre>';
?>
PHP Version = 5.2.4
PCRE Library Version = 7.2 2007-06-19
Array
(
[0] => Array
(
[0] => /package[@name='mypackage'
)
[1] => Array
(
[0] => /package[@name='mypackage'
)
[2] => Array
(
[0] => /class[@name='myclass']
)
[3] => Array
(
[0] => /method[@name='something' and param[1]/typevaluespec='in
)
)