Solved

Removing ^M characters from text documents

Posted on 2002-06-19
1
154 Views
Last Modified: 2010-03-05
I'm a semi-newbie, but I have been working with perl for about a year now.  So bear with me.

I'm writing a script to take html files written in windows and remove the tags.  I've got everything under control except that I can't seem to get rid of some pesky ^M characters.  They're causing the text to lose the format I'm giving it, so they need to be removed.  I've tried to use some regular expressions:
     $text =~ s/^M//g; # Attempt 1

     $text =~ s/\^M//g; # Attempt 2

     $text =~ /.(.*)/g; # Attempt 3 (the ^M seems to be at the start of each line)
     $finished_text = $1;

Well, I've been trying things for a few days now, and am getting nowhere, so if someone could tell me what I'm doing wrong, it would be much appreciated.
0
Comment
Question by:tuxCharon
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 7094538
$text =~ s/\cM//g;
or
$text =~ s/\r//g;
or
$text =~ s/\015//g;
or
$text =~ tr/\xd//d;
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question