Two other examples regarding this generic regex ! In these ones, we’ll even restrict the replacements to each concerned zone before a # character !
Paste the text below in a new tab :
<iden>123456 (START)</iden>
<name>Case_1</name>
<descrip>This is a (short) text to (easily) see the results (of the modifications)# (12345) test (67890)</descrip>
<param>val (250)</param>
<iden>123456</iden>
<name>Case_2</name>
<descrip>And the (obvious) changes occur only in (the) "descrip" tag # Parentheses (Yeaah) OK</descrip>
<param>val (500)</param>
<iden>123456 (END)</iden>
<name>Case_3</name>
<descrip>All (the) other tags are (just) untouched #(This is) the end (of the test)</descrip>
<param>val (999)</param>
In this first example, of single-line <descrip> tags , two solutions are possible :
Use the complete generic regex (?-si:BSR|(?!\A)\G)(?s-i:(?!ESR).)*?\K(?-si:FR) where ESR = # which leads to the functional S/R :
SEARCH (?-s)(?-i:<descrip>|(?!\A)\G)((?!#).)*?\K(?:\x20\(.+?\))
REPLACE Leave EMPTY
=> This time, in addition to only replace in each <descrip>..........</descrip> zone, NO replacement will occur after the # character of each <descrip> tag !
Use the simplified solution and add a ESR condition at the end of the regex, giving this generic variant (?-s)(?-i:BSR|(?!\A)\G).*?\K(?-i:FR)(?=ESR)
SEARCH (?-s)(?-i:<descrip>|(?!\A)\G).*?\K(?:\x20\(.+?\))(?=.*#)
REPLACE Leave EMPTY
However, this other solution needs that all the <descrip> tags contains a comment zone with a # char
Now, paste this other text below in a new tab :
<val>37--001</val>
<text>This-is
-a--very---< # Dashes - - - OK/text>
<pos>4-1234</pos>
<val>37--002</val>
<text>-small----#---example</text>
<pos>9-0012</pos>
<val>37--003</val>
<text>-of-a-text-
which-</text>
<pos>1-9999</pos>
<val>37--004</val>
<text>need
-to-be-
modi
fied # but - not - there</text>
<pos>0-0000</pos>
This second example is a multi-lines replacement, in each <text>.............</text> zone only and also limited to the part before a # char which can be present or not
Of course, we’ll have to use the complete generic regex (?-si:BSR|(?!\A)\G)(?s-i:(?!ESR).)*?\K(?-si:FR) but, instead of a single (?!ESR), we’ll have to use this variant :
(?-si:BSR|(?!\A)\G)(?s-i:(?!ESR_1)(?!ESR_2).)*?\K(?-si:FR)
So, the functional regex S/R becomes :
SEARCH (?-si:<text>|(?!\A)\G)(?s-i:(?!</text>)(?!#).)*?\K-+
REPLACE \x20
=> ONLY IF a sequence of dashes is located in a <text>..........</text> zone AND, moreover, before a possible # char, it will be replaced with a single space character
As you can verify, the third multi-lines <text>.............</text> zone does not contain any # char. Thus, all dash characters, of that <Text> tag, are replaced with a single space char !
Remainder :
You must use, at least, the v7.9.1 N++ release, so that the \A assertion is correctly handled
Move to the very beginning of file, before any Find Next sequence or Replace All operation
Do not click on the step-by-step Replace button