How do I replace )
when it comes after 1, 2, or 3 digits (not chars, and without removing the digit(s) themselves)?
Asked
Active
Viewed 63 times
0

Josh Withee
- 9,922
- 3
- 44
- 62

Markov
- 45
- 6
-
1I can't duplicate this. What are you replacing? The entire string `')'` or the parenthesis only `)`? Can you give a reproducible example? – Jacob H Feb 06 '18 at 18:13
-
sorry this was not clear enough. Yes, I was trying to replace the parenthesis only. – Markov Feb 08 '18 at 00:52
-
I have a text where parentheses are often used, such as (adsf adsf). There are frequent places where you find (reference adsf, 34). I was trying to replace the ) with )\n (introducing a new line, but only in those instances where the 1,2,or 3 digits come right before the ), not other occurences of ) e.g. (reference asdf, 3) or (reference adf, 245). – Markov Feb 08 '18 at 01:00
2 Answers
2
Find what: ((?<!\d)\d{1,3})\)
Replace with: $1
This ensures that the )
comes after 1 to 3 digits (no more, no less).
Just append your replacement text to the end of $1
. For example, if you want to replace it with the word TEST
, your replacement would be $1TEST

Josh Withee
- 9,922
- 3
- 44
- 62
-
1
-
Good point. Updated answer. I just remembered Notepad++ allows negative lookbehinds if they aren't variable length. – Josh Withee Feb 06 '18 at 19:33
-
0
As simple as:
- Find:
((^|[^\d])\d{1,3})\)
- Replace
\1
And don't forget to enable te regular expressions in the panel.
Visit this link to try a working demo.

Tommaso Belluzzo
- 23,232
- 8
- 74
- 98
-
I am trying to replace "abc digit" with "efg digit", but replacing "abc \d" with \1, regexp ON, is removing the digit. e.g. abc 1 and abc 2 are replaced with efg – Markov Feb 17 '18 at 07:06
-
String: `abc 4` - Find: `[A-Za-z]+ (\d)` - Replace: `efg \1` - Result: `efg 4` – Tommaso Belluzzo Feb 17 '18 at 11:51