Regular expression for adding characters before and after numbers

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

Example:

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

result:

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

Numbers, of course, \d+but I want to say that they keep the same numbers when searching.

+5
source share
3 answers

Find what: (\[\d+])

Replace: xxxxxxxxx \1 xxxxxxxxx

enter image description here

+16
source

WITH#:

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

Other languages ​​similar

+2
source

:

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


. regexr

0

All Articles