13

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.

manojlds
  • 290,304
  • 63
  • 469
  • 417
Mike
  • 2,051
  • 4
  • 28
  • 46

3 Answers3

25

Find What: (\[\d+])

Replace With: xxxxxxxxx \1 xxxxxxxxx

enter image description here

manojlds
  • 290,304
  • 63
  • 469
  • 417
5

Regular expression:

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


Refer: regexr

Mukul Aggarwal
  • 1,515
  • 20
  • 16
2

C#:

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

Other languages analogous

Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92