Deleting everything (to end of line) after a certain string

A place to try and solve your RegEx problems.
Post Reply
User avatar
longtalker

Deleting everything (to end of line) after a certain string

Post by longtalker »

Hello everyone,

First of all a big thank you to the makers of TextCrawler, which really is a fantastic software, and exactly what I needed right now (and free as well!).

I was wondering if someone could give me a hand with the regexp that I need to use to do a find&replace across several files. There are rows in my files that end in strings like "A (..)", and I'd like to delete the end of all these rows, such that they just end in "A". I've tried using the following regular expressions: "A +", "A *", "A *\n", to be replaced with "A", however none of them worked, and only the character immediately following the A gets deleted.

Thanks in advance for any help!
User avatar
Fool4UAnyway

Re: Deleting everything (to end of line) after a certain str

Post by Fool4UAnyway »

I've tried using the following regular expressions: "A +", "A *", "A *\n", to be replaced with "A", however none of them worked, and only the character immediately following the A gets deleted.
You want to delete:
A (or whatever, but most likely a word or more specific),
a single space character (based on what you tried),
anything that follows up to the end of the line

In regular expressions that would be:
A (or word/part of sentence)
_ (representing a single space character by an underscore character)
. = any character
* = any number of consecutive occurrence of the preceding expression with none required
\r\n or either single expression as end of the line

Find:
A .*\r\n

Replace by:
A\r\n

...with "A" being more specific than a single character... there may be multiple matches for that on a line!

You will have to replace the newline character(s) to preserve the line endings.
I've tried using the following regular expressions: "A +", "A *", "A *\n", to be replaced with "A", however none of them worked, and only the character immediately following the A gets deleted.
"A +" = A, and all consecutive space characters requiring at least one
"A *" = A, and any number of consecutive space characters if present (none required)
"A *\n" = A, any space characters if present and then a newline character
User avatar
longtalker

Re: Deleting everything (to end of line) after a certain str

Post by longtalker »

Thanks very much, this worked just as I wanted it to!
Post Reply