0

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!

3 Answers 3

1

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".

Sign up to request clarification or add additional context in comments.

8 Comments

I am sorry that I was not clear enough that the numbers are randomly and not only starting with 1. It can start with any number from 0-9. sorry.
No, \1 is only a reference to the content of the first parentheses group. Try it!
Ok! Remember to accept my answer by clicking the green tick!
It may be better to simplify (([0-9])([0-9])([0-9])([0-9])) in steps. Remove unneeded brackets to give ([0-9][0-9][0-9][0-9]). Change to (\d\d\d\d) and finally to (\d{4})
Is it possible to match any size of characters and replace with a quotation marks? I might have this text: Comments use mini-Markdown formatting: The post author will always be notified of your Just wants to add quotation marks so it will look like this: "Comments use mini-Markdown 21formatting:" "The post author w65ill always be notified of your" It's tricky since it contains characters and numbers and strings.
|
0

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.

2 Comments

Thanks for making it generic since it was my fault to bring up an example of starting number of only 1. But starting number could be any number. It worked now.
it's just a back-reference for captured group to mention the first captured group.
0

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

3 Comments

I am sorry that I was not clear enough that the numbers are randomly and not only starting with 1. It can start with any number from 0-9.
The Regex will match any 4-digit number, it does not need to start with 1. The $1 or '\1` is just a reference to what you matches in the first set of () of your regex. ($2 or \2 would match the second set of (), and so on...).
@JustinBieber: added demo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.