1

I have a list like this:

2044
2045
2046
103
106
109

On any line that is 3 digits long only I want to insert a "0" before the second last digit.

2044, 2045, 2046 are left alone and 103 changes to 1003, 1006, 1009.

In Notepad++ Regex I have Find: ^[0-9][0-9][0-9]$ which seems to highlight all the three digit lines, but I am stuck on inserting the 0 before the second last on these lines.

Thank you for your time!

4

You need to make use of Regex "capture groups" (any match between ()), and "backreferences" to get the captured text back (\1 and \2 below).

Have a play on a site like regex101.com, which will also explain the Regex for you:

After:

2044
2045
2046
1003
1006
1009
  • Oh nice! That worked great. Thank you. I will use this a lot. – BDF Mar 26 at 16:57
1

Another way to go without groups (more efficient):

  • Ctrl+H
  • Find what: (?<=^\d)(?=\d\d$)
  • Replace with: 0
  • check Wrap around
  • check Regular expression
  • Replace all

Explanation:

(?<=        # positive lookbehind, zerolength assertion that makes sure we have before current position:
    ^       # beginning of line
    \d      # 1 digit
)           # end lookbehind
(?=         # positive lookahead,zerolength assertion that makes sure we have after current position:
    \d\d    # 2 digits
    $       # end of line
)           # end lookahead

Result for given example:

2044
2045
2046
1003
1006
1009

Screen capture:

enter image description here

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.