2

For instance I am looking for something in a bigger text file - very simple for example a string of three digits with \d{3} . What I want to do is: when notepad++/textpad has found the first matching string in a line (and has replaced it with something else) it should jump immediately into the next line.

How can I accomplish that?

I tried \r\n , but in this case textpad finds not the first string with three digits in the line, but always the last. And notepad++ doesn't find anything at all.

I cannot use ^ either because there are some random words (one, two, three or even foru or five) before the digits I try to find and replace.

Thanks for any help.

Phillip
  • 65
  • 1
  • 2
  • 6

1 Answers1

1

To do that, you have to include all the remaining of your line into the matching pattern.

For example, let's say that you search for \d{3} and have the following data:

qweqwe 123 rrr 445
test tetst
41 423 456

Search for: \d{3}(.*$)

Replace: REPLACEMENT$1

Will give you the following result:

qweqwe REPLACEMENT rrr 445
test tetst
41 REPLACEMENT 456

If you didn't had included the remaining line (.*) the result would be:

qweqwe REPLACEMENT rrr REPLACEMENT
test tetst
41 REPLACEMENT REPLACEMENT

In Notepad++ to make this work, you must leave the ". matches newline" option unchecked.

psxls
  • 6,807
  • 6
  • 30
  • 50
  • Yes this works perfect! Thanks! Why do you use the $ for the end of the line and not the ^ for the start? – Phillip Nov 05 '13 at 00:14
  • You could use `^` too, for example search: `^(.*?)\d{3}`, replace: `$1REPLACEMENT` would produce the same results! Please note that now we had to use `.*?` which is a non-greedy (AKA lazy) match. The only reason I chose the `$` is because if I were to describe it in words, the wording it is closer to your title "find pattern and jump to the next line" than `^` which I would describe as "match the first occurrence of pattern in every line". – psxls Nov 05 '13 at 01:52