JustinBieber
JustinBieber

Reputation: 355

RegEx find & replace adding numbers infront of numbers leaving numbers as it is

I have this:

1200
3701

Trying to get this:

100ct1200
100ct3701

But got this:

100ct([0-9])([0-9])([0-9])([0-9])

Because I used regex in find & replace:
Find: ([0-9])([0-9])([0-9])([0-9])
Replace: 100ct([0-9])([0-9])([0-9])([0-9])

Actually I don't know how to express it to just add 100ct infront of the numbers and leave the rest as-it-is. Help? Thanks!

Upvotes: 0

Views: 211

Answers (3)

jcaron
jcaron

Reputation: 17710

Find: ([0-9][0-9][0-9][0-9])

Replace: 100ct$1 or 100ct\1 depending on the language (not sure what syntax Notepad++ uses).

Demo: http://regex101.com/r/cT1mJ8/1

Upvotes: 0

Avinash Raj
Avinash Raj

Reputation: 174696

Your find and replace commands should be,

Find: ([0-9][0-9][0-9][0-9])
Replace: 100ct$1

$1 or \1 or #1 according to your tool.

Upvotes: 0

Teejay
Teejay

Reputation: 7471

You need to use the following syntax

Find: (([0-9])([0-9])([0-9])([0-9]))

Replace: 100ct\1

Note the parentheses around the whole find expression: \1 refers to their content.

EDIT:

You can also use some shorthands for the Find expression:

Find: (\d{4})

It means "match 4 digits".

Upvotes: 1

Related Questions