need help with Regex

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
SAFO
Forum Newbie
Posts: 2
Joined: Fri Jul 23, 2010 6:50 pm

need help with Regex

Post 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>
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: need help with Regex

Post by JakeJ »

The best help I can give you is to point you here http://gskinner.com/RegExr/.
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: need help with Regex

Post 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...
SAFO
Forum Newbie
Posts: 2
Joined: Fri Jul 23, 2010 6:50 pm

Re: need help with Regex

Post by SAFO »

Thank you all
Post Reply