0

I have had some luck with notepad ++ solving some complex find and replace a lot of similar text in around 8000 documents, but not this particular one:

In a text file I will have a lot of lines that say:

ABKNUMBER001=30422

and I need to change this to:

ABKNUMBER001=6543230422

I need the find and replace to be sure it's only replacing the line if ONLY 5 characters beginning with 3 exist after the '='

For example, this line below would not need to be changed:

ABKNUMBER001=304221

In fact, what I really need is to find anything that matches the lines below where xxx can be any digits 0-9 and yyyy can also be any digits 0-9 (but limited to just 4 digits), as follows:

ABKNUMBERxxx=3yyyy

My list will have entries ABKNUMBER001, 002...999 in each text file and I want to replace any of those 999 entries per text file that have a match for 3yyyy with 654323yyyy - make sense?

1

I want to replace any of those 999 entries per text file that have a match for 3yyyy with 654323yyyy

  • Menu "Search" > "Replace" (or Ctrl + H)

  • Set "Find what" to ^(ABKNUMBER[0-9][0-9][0-9]=)(3[0-9][0-9][0-9][0-9])$ or

  • Set "Find what" to ^(ABKNUMBER[0-9]{3}=)(3[0-9]{4})$

  • Set "Replace with" to \1654\2

  • Enable "Regular expression"

  • Click "Replace All"

    enter image description here

Before:

ABKNUMBER001=30422
ABKNUMBER002=40422
ABKNUMBER004=50422
ABKNUMBER005=60422
ABKNUMBER001=304221

After:

ABKNUMBER001=65430422
ABKNUMBER002=40422
ABKNUMBER004=50422
ABKNUMBER005=60422
ABKNUMBER001=304221

Further reading

  • I am struggling to get matches. I know in my folder I have many files that should match (see a direct copy of the first part of one text file but it is not finding them in notepad++ English/Metric Units= ABKNAME001=Amy ABKNUMBER001=30566 ABKTYPE001=1 ABKNAME002=Cardio ABKNUMBER002=21291 ABKTYPE002=0 – Cheddar Mar 20 '16 at 17:47
  • @Cheddar Is all that data on separate lines? – DavidPostill Mar 20 '16 at 17:50
  • my data is interlaced with a few other non-relevant bits of data. If I use np++ to search just that a single file I get no matches...curious. – Cheddar Mar 20 '16 at 17:52
  • English/Metric Units= ABKNAME001=Amy ABKNUMBER001=30566 ABKTYPE001=1 ABKNAME002=Cardio ABKNUMBER002=21291 ABKTYPE002=0 – Cheddar Mar 20 '16 at 17:53
  • Try replacing $ with [ ]*$. It works for me even with trailing spaces. – DavidPostill Mar 20 '16 at 17:53
2

Notepad++ does Perl regular expressions. This has, in particular, repetition operators:

ABKNUMBER[0-9]{3}=3[0-9]{4}$

I replace your xxx with [0-9]{3} to request exactly 3 digits and yyyy with [0-9]{4} to request exactly 4 digits. In addition I terminate with $ to match the end of the line. You may want to insert a [ ]* in front of the $, in case you are not sure that there are no stray space at the end of the lines.

This answer is based on what I know of regular expressions. I have no np++ at hand to test this, so please test first.

  • I am struggling to get any hits in np++ when finding in files. An excerpt from a known matched file below is not being pulled up. English/Metric Units= 1ABKNAME001=Amy ABKNUMBER001=30566 ABKTYPE001=1 ABKNAME002=Cardio ABKNUMBER002=21291 ABKTYPE002=0 – Cheddar Mar 20 '16 at 17:49
  • Thank you - with your and @DavidPostill help, this is solved. – Cheddar Mar 20 '16 at 17:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.