homepage Welcome to WebmasterWorld Guest from 54.211.219.68
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 / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
trimming data into words with regex
regex headache galore
amznVibe

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3428 posted 6:46 am on Jan 21, 2004 (gmt 0)

I have a weird situation where I can only use a regex expression to do a search/replace to split up a phrase broken by special characters. I need a regex pro, this is beyond my skill (an hour+ on this already!)

the phrase:
a quick~brown fox~jumped over

I'd like to retrive the first words before the ~
the second phrase between the ~
and the last words after the last ~

I got the first one working with s/\~(.*)//g
but the rest are beyond me.

I thought this might work for the second s/\^(.*)~// but no go.

Many thanks for any help!

 

sugarkane

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3428 posted 9:47 am on Jan 21, 2004 (gmt 0)

Not sure if this is what you're looking for, but:

$phrase="a quick~brown fox~jumped over";
$phrase=~/(.*?)~(.*?)~(.*)/;
$part1=$1;
$part2=$2;
$part3=$3;

amznVibe

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 3428 posted 10:04 am on Jan 21, 2004 (gmt 0)

LoL, yep, it was that easy... I figured it out about 30 minutes before you posted. I had not done any regex in months and was a novice to start with. Forgot all I knew. Thanks for the reminder!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI 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