Hi, @alan-kilobrn and All,
Well, here it is ! I found a regex structure and some variants, which do the trick very nicely ;-))
Let’s define these 4 variables :
Srch_Expr = Char|String|Regex
Repl_Text = Char|String|Regex
Opn_Del = Char
End_Del = Char
Then the Search_Replacement_A, which matches any Srch_Expr, ONLY WHEN located between the Opn_Del and the End_Del delimiter(s), is :
SEARCH Srch_Expr(?=[^Opn_Del]*?End_Del)
REPLACE Repl_Text
Rules and Remarks :
The Opn_Del and End_Del delimiters represent, both, a single char, which may be :
Characters already present of the current file
Characters presently absent in current file and manually added by the user ( Verify with the Count feature they are new chars ! )
In case, of added delimiters, use, preferably, the Search_Replacement_B, below, which deletes these temporary delimiters, at the same time :
SEARCH Opn_Del|(Srch_Expr)(?=[^Opn_Del]*?End_Del)|End_Del
REPLACE ?1Repl_Text
The Opn_Del and End_Del delimiters must not be identical. If NOT ( usually, cases "...." or '....' ), perform the following regex S/R, first :
SEARCH Delim(.+?)Delim
REPLACE Opn_Del\1End_Del
Then, execute the Search_Replacement_C, which rewrites, as well, the initial double delimiters Delim :
SEARCH Opn_Del|(Srch_Expr)(?=[^Opn_Del]*?End_Del)|End_Del
REPLACE ?1Repl_Text:Delim
In case that the last zone Opn_Del......End_Del ends at the very end of current file, the End_Del delimiter, of the last zone, can be omitted and you’ll use the Search_Replacement_D, below :
SEARCH Srch_Expr(?=[^Opn_Del]*?(End_Del|\z))
REPLACE Repl_Text
The different zones, between delimiters, must be complete, with their matched different delimiters ( Open_Del......End_Del )
The different zones, between delimiters, may be juxtaposed but NOT nested
A zone can lie in a single line or split over several lines
Srch_Expr must not match the Opn_Del delimiter, or part of it
As an example, let’s use the license.txt file and define :
Opn_Del &
End_Del #
Srch_Expr \w+
I previously verified that, both, these two symbols do not exist in the license.txt file
Place
one or
several zones
&......#,
anywhere in this file. The zones may be split on
several lines, with the
OplDel & in a line and an
End_Del # on a
further line
So, the appropriate search regex_A is :
SEARCH \w+(?=[^&]*?#)
And imagine that we want to surround any word with strings [-- and --], in zones &............#, ONLY. Hence, the replace Regex_A is :
REPLACE [--$0--]
With the same delimiters, let’s suppose that we want, this time, to find any single standard char, so the regex (?-s). and to replace it with an underscore _ char
However, regarding the rules above, this regex should not match the Opn_Del delimiter. This can be achieved with the regex (?-s)(?!&)., giving the following Search_Replacement_A :
SEARCH (?-s)(?!&).(?=[^&]*?#)
REPLACE _
Now, Alan I also found a regex which works when delimiters are simple words as for instance, STT and END and not single characters :
Regex_E =
Srch_Expr(?=(?s-i:(?:(?!Opn_Del).)*?End_Del))
Unfortunately, due to the negative look-ahead syntax, (?!Opn_Del).), this regex bugges, even with the light license.txt file :-(( You know : the final wrong “all contents” match ! But it works nice when few lines are involved !
The safe solution, in that case, is to replace word delimiters with char delimiters, first ( for instance STT -> & and END -> # )
Finally, a possible @mugsys-rapSheet’s solution, much shorter, using the generic Search_Replacement_C, could be :
SEARCH &|(\x20)(?=[^&]*?#)|#
REPLACE ?1_:"
Of course, assuming this text :
& C:\xxx\name with spaces.txt #
Then, the leading and trailing spaces, around the absolute paths, would not be deleted anymore but just replaced with _ characters. Thus, the final text would be :
"____C:\xxx\name_with_spaces.txt____"
Best regards,
guy038