Page 1 of 1

need help with Regex

Posted: Fri Jul 23, 2010 8:47 pm
by SAFO
Need some quick help with building a regular expression. Here is a sample of the soap message, I need to extract the URL between the 2 tag wsa:From & wsa:Address. ie i want "http://emf.abc.com/xyz/from/Adapter/" from the below message. Any suggestion ?

<s11:Header>
<wsa:MessageID s11:mustUnderstand="1">uuid:593C8EFC-76BA-11D9-AAC8-91EC5E497717</wsa:MessageID>
<wsa:To s11:mustUnderstand="1">http://emf.abc.com/xyz/to/Adapter/</wsa:To>
<wsa:From s11:mustUnderstand="1">
<wsa:Address>http://emf.abc.com/xyz/from/Adapter/</wsa:Address>
</wsa:From>
<wsa:ReplyTo s11:mustUnderstand="1"> <wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/a ... sa:Address>
</wsa:ReplyTo>
<wsa:FaultTo s11:mustUnderstand="1">
<wsa:Address>http://schemas.xmlsoap.org/ws/2004/03/a ... sa:Address>
</wsa:FaultTo>

</s11:Header>

Re: need help with Regex

Posted: Sat Jul 24, 2010 12:08 am
by JakeJ
The best help I can give you is to point you here http://gskinner.com/RegExr/.

Re: need help with Regex

Posted: Sat Jul 24, 2010 11:09 am
by ridgerunner
Assuming you are using PHP, try this...

Code: Select all

$pattern = '%<wsa:From[^>]*+>\s*+<wsa:Address[^>]*+>(.*?)</wsa:Address>\s*+</wsa:From>%i';
$count = preg_match_all($pattern, $contents, $matches, PREG_PATTERN_ORDER);
// $matches[1] is an array containing $count "From" links
echo('Number of links found = '. $count ."\n");
for ($i = 0; $i < $count; $i++) {
  echo($matches[1][$i] ."\n");
}
Hope this helps! :)

p.s. Next time, try to pick a more useful name for the thread title. "Need help with regex" is pretty lame...

Re: need help with Regex

Posted: Sat Jul 24, 2010 9:37 pm
by SAFO
Thank you all