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>
need help with Regex
Moderator: General Moderators
Re: need help with Regex
The best help I can give you is to point you here http://gskinner.com/RegExr/.
- ridgerunner
- Forum Contributor
- Posts: 214
- Joined: Sun Jul 05, 2009 10:39 pm
- Location: SLC, UT
Re: need help with Regex
Assuming you are using PHP, try this...
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...
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");
}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
Thank you all