How can I delete rest of the line after a specific string?

12

7

I'm looking for a way to search for a specific string e.g. '=UUID:' and delete it and all following characters per line. I would prefer a way/macro/addon for notepad++. But all other tools or scripts are welcome :)

Before

 *://81.88.22.6/*=UUID:63969B2469B7A94EBBDBD7CB5B9C00BA
 *://*-ad.cgi*=UUID:3C8EFF48B674CC42BF5B6E2B7BA820E7
 *://*-ads/*=UUID:0D6CF7D5BE3F034C8A136CC99A074406

Note that the numbers are always different per line so you couldn't do a search 'n replace with them.

Should look like this after

*://81.88.22.6/*
*://*-ad.cgi*
*://*-ads/*

nixda

Posted 2011-01-15T09:44:51.773

Reputation: 23 233

Answers

26

Search mode regular expression, Find

=UUID:.*

Replace with nothing.

Daniel Beck

Posted 2011-01-15T09:44:51.773

Reputation: 98 421

2The point between both expressions did the trick. Thank you very much. – nixda – 2011-01-15T10:01:33.657

@nixdagibts that's not a "point between both expressions". It searches for =UUID:, followed by any character (.) any number of times (*), effectively "any sequence of characters", ending at the line break. – Daniel Beck – 2011-01-15T11:26:36.713

3@nixdagibts you could, in the future, try =UUID:[0-9A-F]{32} to prevent false positives (i.e. removing something you'd want to keep) – Daniel Beck – 2011-01-15T13:15:34.603

3

It's easy. Your question:

*://81.88.22.6/*=UUID:63969B2469B7A94EBBDBD7CB5B9C00BA
*://*-ad.cgi*=UUID:3C8EFF48B674CC42BF5B6E2B7BA820E7
*://*-ads/*=UUID:0D6CF7D5BE3F034C8A136CC99A074406

My answer:

[=].*

Result:

*://81.88.22.6/*
*://*-ad.cgi*
*://*-ads/*

Explanation:

= character, represent the character you want to remove
.* characters, represent all the characters after that

That's it.

andreas

Posted 2011-01-15T09:44:51.773

Reputation: 39

Basically the same as Daniel's answer. He's suggest searching for =UUID: and delete the rest of the line with .*. You minimized it by only searching for the first character =. Additionally there's no need to use a capture group [] – nixda – 2014-04-10T06:36:27.750

-1

Using find and replace:

  1. Hit CTRL-H to open the Replace dialogue box
  2. enter =UUID:.* into Find what
  3. leave Replace with empty
  4. Select Regular expression and .matches newline
  5. Click on Replace

Kamleshkumar G

Posted 2011-01-15T09:44:51.773

Reputation: 1

1You are replicating another answer – yass – 2017-04-24T16:49:29.150