Welcome to WebmasterWorld Guest from 50.19.53.104

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

trimming data into words with regex

regex headache galore

     

amznVibe

6:46 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

9:47 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

10:04 am on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month