I have some text that I just realized is screwing everything up because
it contains the ^M character (control-M). I have tried using all kinds
of regexp expressions to find and remove it but it is evasive
What is the best way to find and remove the pesky ^M character from
text?
Hi John,
str = "123^M56"
newstr = str.sub(/^M/, '')
Note - for the substitution, you enter the '^M' character using Ctrl+v+m (-
or at least I do on Solaris.)
~mm
ยทยทยท
On Fri, Nov 28, 2008 at 2:57 PM, John Victor <john@sflistdb.com> wrote:
I have some text that I just realized is screwing everything up because
it contains the ^M character (control-M). I have tried using all kinds
of regexp expressions to find and remove it but it is evasive
What is the best way to find and remove the pesky ^M character from
text?
A simpler method, applicable if the c-m is coming from line ends
ruby -ne 'puts chomp' xxx > yyy
HTH
Robert
ยทยทยท
On Fri, Nov 28, 2008 at 8:57 PM, John Victor <john@sflistdb.com> wrote:
I have some text that I just realized is screwing everything up because
it contains the ^M character (control-M). I have tried using all kinds
of regexp expressions to find and remove it but it is evasive
What is the best way to find and remove the pesky ^M character from
text?
I never realized how badly ^M was screwing me up all these years when
trying to match with regular expressions. I wish there was a way to see
all the end of the line characters, carriage returns and new line
without having to guess if they exist and using trial and error for
hours when doing regexp matches.
I never realized how badly ^M was screwing me up all these years when trying to match with regular expressions. I wish there was a way to see all the end of the line characters, carriage returns and new line without having to guess if they exist and using trial and error for hours when doing regexp matches.
vic
On Linux, OS X, and other *ix systems, you can use cat -v. In Ruby, String#inspect will show special characters escaped, so you can just use
p str
to see special characters. A newline shows up as "\n", for example.
Thanks for the String#inspect, that really helps.
I am trying to do a regexp match on the first line only of this text, I
used the output from text.inspect: