-1

I have this very long file with many lines like this:

MeshFile=brosm05028.gmt CollTarget=True HATTarget=True LODOut=(500.0)

What I am trying to do is to use notepad++ find and replace to set the CollTarget to False of every MeshFile named brosm[XXXXX].gmt. The line of text should end up looking like this:

MeshFile=brosm05028.gmt CollTarget=False HATTarget=True LODOut=(500.0)

I know how to use ".*" to find but I don't know how to keep the unique numbers when I replace. Thanks in advance.

3
  • regex101.com is a useful site where you can test regular expressions. The flavour that NP++ uses is "PCRE (PHP <7.3)" IIRC.
    – Gantendo
    Commented Aug 15, 2023 at 13:20
  • What type of character is [XXXXX]? Only numeric, alphanum, other? Is it always 5 characters?
    – Toto
    Commented Aug 15, 2023 at 14:49
  • @Gantendo: Not really, Npp uses boost regex flavour. There are some differences comparing to PCRE
    – Toto
    Commented Aug 15, 2023 at 14:58

3 Answers 3

0

To keep part of the text you find in the replacement intact, you would use capture groups.

Find (with RegEx):

(MeshFile=brosm.*.gmt CollTarget=)(True)

And replace with:

\1False

enter image description here

1
  • 1
    Yes this is the one, Many thanks, you are a life saver Commented Aug 15, 2023 at 23:19
0

A more specific regex here would be:

^(MeshFile=brosm\d{5}\.gmt CollTarget=)True

Explantation:

  • ^ to ensure start of the line, if needed
  • \d{5} to capture 5 digits, which you specified as required file format in your question. If instead you meant any number of digits, then \d+ can be used.
  • \. escapes the dot just in case
  • everything between () gets captured as \1 and thus you can replace with:
\1False
0
  • Ctrl+H
  • Find what: MeshFile=brosm.+?\.gmt CollTarget=\KTrue
  • Replace with: False
  • TICK Wrap around
  • SELECT Regular expression
  • UNTICK . matches newline
  • Replace all

Explanation:

MeshFile=brosm          # literally
.+?                     # 1 or more any character but newline
\.gmt CollTarget=       # literally
\K                      # forget all we have seen until this position
True                    # literally

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .