Re: substitution
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 13 Feb 2006 08:28:43 -0800
Michael Gargiullo wrote:
The carrot is a special char, so if you want that to be included as a
carrot and not a "start of string" marker, it too would have to be
escaped.
To do the replace that you wanted, I'd do the following.
I have a text string = "^0176 ^0176"
$_=s/\^0176\ \ \^0176/\^0176\ \ /;
This will substitute your exact string of ^0176<space><space>^0176 with
the exact string ^0176<space><space>
That will assign $_ to be the result of the s/// operation (ie, either
1 or ''). You meant the =~ operator, not the = operator.
A space character is not special in a regular expression (unless you
choose to use the /x modifier), so there's no need to backlash it.
Neither the ^ nor the space character are special in a double quoted
string, so there's no need to backslash those in the replacement.
To correct your expression:
$_ =~ s/\^0176 \^0176/^0176 /;
However, I would most likely write this like so:
s/((\^0176) )\2/$1/;
Or maybe even:
s/(?<=\^0176 )\^0176//;
Or:
s/(?<=(\^0176) )\1//;
If you're not keeping your trailing spaces, make sure your not chomping
or chopping your variable later in your script.
chomp removes newlines. It has nothing to do with spaces.
Paul Lalli
.
- References:
- RE: substitution
- From: Michael Gargiullo
- RE: substitution
- Prev by Date: Re: single step - debug mode
- Next by Date: Re: substitution
- Previous by thread: RE: substitution
- Next by thread: Re: substitution
- Index(es):
Relevant Pages
|