Re: search and replace using regex
From: Drieux (drieux_at_wetware.com)
Date: 12/03/03
- Next message: Wiggins D Anconia: "RE: Timing several processes"
- Previous message: Tom Kinzer: "RE: Timing several processes"
- In reply to: Rob Dixon: "Re: search and replace using regex"
- Next in thread: R. Joseph Newton: "Re: search and replace using regex"
- Reply: R. Joseph Newton: "Re: search and replace using regex"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 3 Dec 2003 10:20:52 -0800 To: Perl Perl <beginners@perl.org>
On Dec 3, 2003, at 7:06 AM, Rob Dixon wrote:
[..]
>> remember that those double quotes will allow things
>> to be 'interpolated' - which is not what you want.
>
> No they won't: they're not string delimiters in this context
> so they'll be treated as any other non-special character between
> the real s/// slash delimiters.
>
> Rob
Minor Blonde Hair Moment On my phrasing.
Thanks You for the good catch!
let's look at some code:
my $foo = q|" _</pat stuff _</pat> other stuff|;
print "$foo \n";
$foo =~ s|" _</pat|"</pat"|g;
print "$foo \n";
which will generate
" _</pat stuff _</pat> other stuff
"</pat" stuff _</pat> other stuff
Now IF the OP really wanted that sort of case,
then while a bit wacko, it will work.
So the question is whether that '"' double
quote token is a part of the pattern that
will be searched for, or is it the sort of
classic cut and paste problem of say
my $foo = " _</pat .... _</pat";
and in the heat of trying to sort out what was
scragged in the RegEx, hoping over the line to
$_ =~ s/"_\</pat"/"\</pat"/gi; #g for every occurrence, i for
hoping that by adding in more tokens it
would make it go zoom zoom..
I think that were you or I working the RE
and we wanted to remove ' _<' and replace it
with mere '<' we would have done say
$_ =~ s| _<|<|g;
Or we might use say
$_ =~ s|\s*_<|<|g;
to clean out the preceeding 'white space'...
ciao
drieux
---
- Next message: Wiggins D Anconia: "RE: Timing several processes"
- Previous message: Tom Kinzer: "RE: Timing several processes"
- In reply to: Rob Dixon: "Re: search and replace using regex"
- Next in thread: R. Joseph Newton: "Re: search and replace using regex"
- Reply: R. Joseph Newton: "Re: search and replace using regex"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|