2

I want to replace increment number using regular expression in TextPad. I have below code and I want increment number between tag <EndToEndId> and </EndToEndId> and number should remain 8 digits.

        <PmtId>
           <EndToEndId>80000001</EndToEndId>
        </PmtId>
        <PmtTpInf>
              <Prtry>PM</Prtry>
        </PmtTpInf>
       <PmtId>
       <PmtId>
           <EndToEndId>80000002</EndToEndId>
        </PmtId>
        <PmtTpInf>
              <Prtry>PM</Prtry>
        </PmtTpInf>
       <PmtId>
       ......
       <PmtId>
           <EndToEndId>800000010</EndToEndId>
        </PmtId>
        <PmtTpInf>
              <Prtry>PM</Prtry>
        </PmtTpInf>
       <PmtId>

I have tried myself to come up with solution but after 80000009, it gives 800000010 which is 9 digit number.

I have provided below regular expression in Find And Replace option in TextPad.

Find What: (<EndToEndId>).*?(</EndToEndId>) Replace With: (<EndToEndId>)\i(</EndToEndId>)

I have searched similar solution on Stackoverflow using Notepadd++ from Notepad++ incrementally replace but it doens't give increment number when there are other tags like <PmtId>, <PmtTpInf>

Could you please help me to solve this issue as I have tried myself a lot and now asking on Stackoverflow. Thank you.

Jayveer Parmar
  • 500
  • 7
  • 25
  • It's possible, in two steps following this [answer about incrementing numbers](https://stackoverflow.com/a/31599758/1507014) – Bentoy13 Dec 21 '18 at 08:19
  • You can't do that, in your case, with a text editor. You have to write a script in your favorite scripting language – Toto Dec 21 '18 at 10:27

1 Answers1

1

Do two passes.

The first pass as you are currently doing, producing results like:

80000001
80000009
800000010
800000099
8000000100
8000000999

then a second pass to correct the lengths:

Search:  80+(\d{6})\b
Replace: 8$1

Which produces the following result from the above sample intermediate output:

8000001
8000009
8000010
8000099
8000100
8000999
Bohemian
  • 412,405
  • 93
  • 575
  • 722