Forum Moderators: coopster & phranque

Message Too Old, No Replies

Need help with PCRE (search and replace)

         

Joe Belmaati

10:02 am on Nov 2, 2004 (gmt 0)

10+ Year Member



I am doing some search and replace. I am using this line:

$line =~ s/Monday¦Tuesday¦Wednesday¦Thursday¦Friday¦Saturday¦Sunday//g;

What I am trying to do, is to remove the weekdays, however I want to only remove those words if they appear at the beginning of a string i.e.

Monday November 1st

becomes

November 1st

The crew moved in on Monday

stays the same

How would I rewrite $line to accomplish what I want?

Sincere thanks.
Joe Belmaati
Copenhagen Denmark

upside

10:01 am on Nov 3, 2004 (gmt 0)

10+ Year Member



The ^ matches at the beginning of a string.

$line =~ s/^(Monday¦Tuesday¦Wednesday¦Thursday¦Friday¦Saturday¦Sunday)\s//g;

If your string has multiples lines and you want to match on each line then you'll have to loop for each line.