0

I need to replace several different specific words/values in one string, for example:

1), 2), 3), A., B., C., etc.

They can all be replaced with the same thing - nothing, i.e. no value entered into the replace box.

But I need to do it without Notepad++ deleting any individual aspects of the "words." For example, it should delete 1), 2), A., B. without deleting any individual value like 1, 2 (numbers on their own), ) (parenthesis on their own), A, B (letters on their own) or . (periods on their own).

So far I tried entering this into the find box:

(1.)|(2.)|(3.)|(A.)|(B.)|(C.)

But it deleted every single number 1, 2 or 3, every period and every capital A, B or C.

2 Answers 2

1

This regex should work for you:

([1-3]|[A-C])(\.|\))

You basically ignored the fact that there are special characters like . (any character) and ) (closing of a group) that need to be escaped in regexes. You can also group characters with [A-C] syntax, which means A to C.

Demo with step by step explantation

If you need all numbers starting from 1 and capital characters (so typical simple enumeration) then you can replace with:

([1-9]\d*|[A-Z])(\.|\))

Where \d* is just shorthand for [0-9]*, so optional multiple digits, following a number that's not 0 ([1-9]).

With Roman numerals as per comment (not necessarily valid ones):

([1-9]\d*|[A-Z]|[CDILMVX]+)(\.|\))

So basically just repeating valid characters in a character group. If ou need tocheck for valid ones then searchingis your friend and this is a random example of a complex regex that you need to add as alternative.

8
  • That's almost exactly what I was looking for, thank you! How do I also get this to work with Roman numerals as well, any ideas?
    – Mike M
    Apr 20, 2023 at 3:11
  • Ok, thank you. Do you have any idea how it can be done with Roman numerals?
    – Mike M
    Apr 20, 2023 at 18:25
  • Ok great, thank you! Is there any way to get rid of the space that it leaves at the beginning of each line?
    – Mike M
    Apr 20, 2023 at 21:03
  • I don't know which space. Once again, not specified in the question.
    – Destroy666
    Apr 21, 2023 at 6:24
  • I want the values that are to be replaced simply deleted, when I run the code in the find box, it deletes those values great, but it replaces them with a blank space at the beginning of every line. It should just delete the value (replacing it with nothing).
    – Mike M
    Apr 21, 2023 at 18:13
0

Try the following regex:

^(\d+|[A-Z])\)

This regular expression can be broken down as follows:

^: This asserts the position at the start of a line.
(: This opens a capturing group.
\d+: This matches one or more digits (0-9).
|: This is the alternation operator, working like an OR in regular expressions.
[A-Z]: This matches a single uppercase letter from A to Z.
): This closes the capturing group.
\) : This matches a closing parenthesis.

So, this regular expression will match any string that starts with one or more digits (0-9) or a single uppercase letter (A-Z), followed by a closing parenthesis. Some examples of matching strings would be:

"1)"
"23)"
"A)"
"Z)"
1
  • Thanks. How do I do that for periods (1. 2. 3. A. B. C.) as well?
    – Mike M
    Apr 21, 2023 at 20:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .