Need help with Regular Expressions and Hexadecimals
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Need help with Regular Expressions and Hexadecimals
I'm using VIM and I have a screwy html file.
It is in Unix format... but a stupid piece of crap Microsoft program added a bunch of carriage returns CR to it. Most of the lines are ended with a CR + LF but the microcrap proggy added an extra CR to some lines.
I just want to search and replace the lines using regular expressions in VIM. But the search fails whenever it encounters the crap that micro$oft put in.
Here's what it looks like in both ascii and hex.
<p>
<pre>
here's the hex stuff that you can't see (btw 0d = CR, 0a = LF)
<p>0d 0a 0d
<pre>
the extra '0d' at the end was inserted by the micro$oft program. Normal Unix files have just 0d 0a to end and start a line.
the regex command i used in ViM to try to find it was:
/<p>(.|\n)*<pre>
but it fails to find the pattern... therefore I can't use a regex substitution expression on it. (plan to do it on multiple files)
Does anyone know how to use the \x hexadecimal character class that Vim's regex comes with?
When I usually vim a windows formatted text file I see the "^M" character at the end of the line. I'm not sure why you do not see that. I use the command ":s/^V^M//g" to get rid of the windows crap. Note that the <ctrl>V will not appear, it just allows you to enter the <ctrl>M correctly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.