With a bit of help from HamZa, I came up with this:
Replace:
(S#.*?;) (?=.*?</ns)
with:
\1
Then just hit Replace All until no replacements are made any more (each find includes the S#
, so you can only do one replacement for each of these strings at a time), or you can write a simple macro to find and replace (all?) and run that as many times as required.
If this string of yours is on its own line, you should also include start (^
) and end ($
) of line indicators:
^(S#.*?;) (?=.*?</ns$)
Explained: (source)
NODE EXPLANATION
--------------------------------------------------------------------------------
( group and capture to \1:
--------------------------------------------------------------------------------
S# 'S#'
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
; ';'
--------------------------------------------------------------------------------
) end of \1
--------------------------------------------------------------------------------
' '
--------------------------------------------------------------------------------
(?= look ahead to see if there is:
--------------------------------------------------------------------------------
.*? any character except \n (0 or more times
(matching the least amount possible))
--------------------------------------------------------------------------------
</ns '</ns'
--------------------------------------------------------------------------------
) end of look-ahead
If Notepad++ supported variable-length look-behinds (at least it doesn't in 6.4.5), you could've replaced (?<=S#14.*?); (?=.*?</ns)
with ;
(and just have done one Replace All).