14

I have a list of numbers between square brackets, and I need to add words before and after the exact numbers (i.e. keep the same numbers). I use notepad++ to replace, but if you have a solution with other program please advise.

Example:

text [121] othertext
moretext [16] othertextmore
andtext [5940] othertextplus

outcome:

text xxxxxxxxx [121] xxxxxxxxx othertext
moretext xxxxxxxxx [16] xxxxxxxxx othertextmore
andtext xxxxxxxxx [5940] xxxxxxxxx othertextplus

The numbers are of course \d+ but I want to tell it to keep the same numbers when looking.

1
  • While the regex sill stay the same, the code will change: WHich Language? Commented Dec 24, 2011 at 10:48

3 Answers 3

25

Find What: (\[\d+])

Replace With: xxxxxxxxx \1 xxxxxxxxx

enter image description here

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

4 Comments

@Mike - You can accept as answer by clicking on the tick on the left.
No need for parentheses if you're going to use the entire match anyway - replace with xxxxxx \0 xxxxxx.
Really? Interesting but not surprising given Notepad++'s lackluster regex support.
don't forget to put your search statement into parenthesis
5

Regular expression:

Find regex = \[\d+\]
Replace regex = xxxxxxxxx$&xxxxxxxxx


Refer: regexr

Comments

2

C#:

line=Regex.Replace(line,@"([^\[])(\[\d+\])(.*)","$1xxxxxxxxx $2 xxxxxxxxx$3");

Other languages analogous

Comments

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.