I have a very basic question which i just can not get my head around. I do have a text document like this:

This is 5 a test!
This 3 is a test!
This is a 9 test!

and i want it to look like this:

This is 5c a test!
This 3c is a test!
This is a 9c test!

Means i want to add a 'c' to every number i find. I tried this:

Find what: [0-9]+]
Replace with: $1c
Search Mode: Regular expression

but i am obviously doing something wrong because it is not working. Help would be appreciated. Thank you!

  • 3
    Just out of curiosity: Why did you try [0-9]+] with those strange unmatched brackets? – Heinzi Oct 8 '18 at 14:22
  • 2
    @Heinzi Betting it's a typo in the question, given the proximity of +, ] and Enter on many keyboards. – Lightness Races in Orbit Oct 8 '18 at 15:15

You almost got it right.

You want to search for ([0-9]+)
And replace that with $1c

You use ( ) to create a capture group, so $1 works.

Alternatively, you can replace with $0c instead, then you don't need to use a capture group.

  • 2
    It works perfectly fine. Thank you very much ;) – user3877230 Oct 8 '18 at 11:00
  • Just curious if there's a difference in that pattern and looking for \d+? – BruceWayne Oct 9 '18 at 0:20
  • 2
    @BruceWayne Depending on yoru regex flavour, \d can match Unicode digits from other scripts. Note that this is not the case for PCRE, which is apparently what Notepad++ uses. In any case, I'd usually favour \d if I want numerical digits, but [0-9] if I explicitly want those characters (e.g. when scraping a defined format that's limited to ASCII characters). – Bob Oct 9 '18 at 0:37
  • Indeed, \d would've worked just as well. I kept the [0-9] syntax because OP already tried that, and the other answer uses \d. – LPChip Oct 9 '18 at 7:21
  • Ctrl+H
  • Find what: \d+
  • Replace with: $0c
  • check Wrap around
  • check Regular expression
  • Replace all

Result for given example:

This is 5c a test!
This 3c is a test!
This is a 9c test!
  • What does wrap around do? – Ooker Oct 9 '18 at 13:18

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.