Re: substitution



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

.



Relevant Pages

  • Re: Opening a Word doc using a command button on a form.
    ... Exit Sub ... string (I have already tried _ underscore in all the spaces in the existing ... about locating the app which handles DOC extensions and where it is located. ... not recognising the space character. ...
    (microsoft.public.access.formscoding)
  • Re: How to use the Trim function?
    ... Mike Williams wrote: ... I think Michael C wanted to do that in case there were some Chrat the end of the string which would appear to be spaces but which would not actually be a space character and which would therefore be ignored by the RTrim function. ... You'll find that when the phrase "rum and Coke" gets to the end of the visible line it will wrap as a complete group onto the next line, so that "rum and Coke" are never separated. ...
    (microsoft.public.vb.general.discussion)
  • Re: trim, chr(10)
    ... (leave blank or a space character if you want) ... Add this recorded code to the top of your existing macro that trims the values. ... I'm trying to clean out some extra spaces in my data. ... Dim v As String, val As Double ...
    (microsoft.public.excel.programming)
  • Re: trim, chr(10)
    ... (leave blank or a space character if you want) ... Add this recorded code to the top of your existing macro that trims the values. ... I'm trying to clean out some extra spaces in my data. ... Dim v As String, val As Double ...
    (microsoft.public.excel.programming)
  • Re: Removing spaces in filenames
    ... wouldn't there be a space character after the equals sign for the ... delims parameter, as in "delims= "? ... I didn't proof the rest of the script. ... where you were taking out the spaces from the string. ...
    (microsoft.public.windowsxp.general)