PAGE2GO2 HOME | INTERNET NEWS

LeighExchange - Free Advertising Network Stock Research at Internet Speed

Re: Need help with a Regex substitution

 List
Subject: Re: Need help with a Regex substitution
Poster: DeVliegendeHollanderdevliegendehollander@attempt-at-not-applicable-domain-name.com
Date: Fri, 23 Mar 2007 22:23:04 +0100
Related Postings: 1 2 3 4
The sentient life form Paul posted the following:


> 3: time_line =~ s/(^\d+\/)0/\1/;
> --- ...
>
> ==> What does line 3 do??

(^\d+\/)

^ is start of line \d+ is 1 or more digits \/ is an escaped /, which is i.e. a /

what matches between the braces ( and ) gets put in $1, which is also accessible as \1

so one or more digits from the start of the line and a / character are matched and put in $1 (accessible via \1 too).

The 0 that follows in the regexp is outside the braces and not put in $1, hence the \1 in the substitute part of the regexp only contains the digits and /, without a 0 following, hence the is removed.

So it removes the 'second' zero in the string.

 

Page2Go2.com is not responsible for content of this message.