Monday, November 16, 2009

My favorite Regular Expression for deleting a line at a time

Ok, so you probably know the power of regular expressions or regex. One of the great things about regex is that with most modern text editors (and even some old classic ones) you can use them to do quick editing over a large file.

My favorite (and this will work in Visual Studio) is for removing lines at a time based on some match.

Let's say we want to select (most likely for removal) any line from a file that has the word Bart in it. Our regex would look like this:


The \n indicates new line. If you left off the \n the line would be selected without the new line character. If you are doing a replacement (such as with nothing to delete the line) and leave off the \n the line is selected but not the return character so for removing the text, a blank line would still exist in the file, whereas including the \n will delete the entire line from the file.


ukhelpdesknumber said...

All kind of Technical help and Support for your Dell Printer and is available with Epson Printer Support Number . Just give us a call 0800-098-8371 for Epson printer support number Uk.

juwai said...

This post is very usefull for me. A lots of thanks for sharing this informative post.

hp printer support

Antivirus Support Number UK 0800-090-3234 said...

Superb post. Many thanks for discussing valuable content material.
AVG Helpline Number UK
AVG Support Number UK

Technical Support UK 0800-090-3234,3242 said...

Very interesting post. Thank you for sharing..
Need help for kodak printer you can call with kodak Printer Support Number UK 0800-090-3234 in UK