homepage Welcome to WebmasterWorld Guest from 54.205.14.21
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
preg replace for a SIP URI
What I have isn't quite there....
trillianjedi




msg:4338675
 9:12 pm on Jul 12, 2011 (gmt 0)

Hi all,

Can anyone help me with this PREG_REPLACE?

I'm trying to detect a SIP URI (kind of link an email address) which can be in what I'm parsing ending either with a ] or a ;.

Like so:-

sip:me@example.com;

or:

sip:me@example.com]

So I need a reg-ex that will either/or for the square bracket or a semi-colon.

This is what I have so far:-


$line = preg_replace('#sip:(.*)\@(.*)\.(.*)[\];]#', "<span class=\"orange\">sip:$1@\\2.\\3</span>]", $line);

This doesn't break on the semi-colon as I intend, although it works on the close square bracket.

Any ideas?

Thanks!

 

g1smd




msg:4338686
 9:35 pm on Jul 12, 2011 (gmt 0)

The .* pattern means "match everything until the end of the input". Having done that, you then want to match "everything" again a further two times. That is not possible.

This will parse a lot faster:
'#sip:([^@]+@([^.]+\.)+[^.;\]]+[;\]])#'
trillianjedi




msg:4340553
 6:20 pm on Jul 17, 2011 (gmt 0)

Thank you!

Got it working nicely with your steer. Sorry for the delay in replying - went and got sick (probably too much RegEX :) ).

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved