In Notepad++, replace:
( # Capturing group consisting of
^\[ # a square bracket at the beginning of line,
[^[\]]* # 0+ non-bracket characters, then
\]$ # a closing bracket at the end of line,
) #
| # or
! # a literal '!'
with:
\1
This matches all square-bracketed strings and exclamation marks, but since we're capturing the former and add that back, only the exclamation marks will be removed.
Try it on regex101.com.
If the brackets are not guaranteed to be at the beginning/end of line, simply remove ^
and $
: (\[[^[\]]*\])|!
. Note that this may match square-bracketed multi-line strings:
[some tex!t !]
[som!e text !
!some text !
] ! foobar
...becomes:
[some tex!t !]
[som!e text !
!some text !
] foobar
Try it on regex101.com.
To limit the match on one line, add a \n
to the character class: (\[[^[\]\n]*\])|!
.
Try it on regex101.com.
Alternatively, use (*SKIP)(*FAIL)
to forgo the first part, as suggested by bobble bubble: \[[^[\]\n]\](*SKIP)(*FAIL)|!
.
Try it on regex101.com.