Hello, @scott-sumner and All,
I’ve studied the general case of searching a specific character, ONLY IF, located inside a range of characters with delimiters.
Now, two cases are possible :
Case A : an area with a same starting and ending character, as, for instance, '.....' or "....."
Case B : an area with a different starting and ending character, as, for instance, (.....), [.....], {.....} or <.....>
Notes :
For our discussion, we are supposed to look for the colon character
For case A, I chose the double quotes delimiter ", as common boundary
For case B, I chose the start delimiter < and the end delimiter >
Let’s begin with the easier form !
Case B : A possible regex would be :
SEARCH :(?=[^<\r\n]*>)
REPLACE Any string or character, even EMPTY
Note that this regex looks for a colon character, ONLY IF followed by a range, possibly empty, of characters, different from the first delimiter < and from the EOL characters \r and \n , till the ending delimiter >
On the test example, below, the regex finds all colon characters, located inside the <.....> areas exclusively ( the ones which are underlined ) Fine !
1:23:<This:is a: tiny>text:to :see<if :my :logic:>is: correct:<I: hope:that>: all: will:be<::fine,: indeed>: ! :<:>78:9
¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯¯ ¯ ¯
Now, in case A, the annoying thing is that it’s impossible to distinguish the two delimiters ! So, we’re going to cheat a bit ! First, we’ll replace, for instance, any area "....." by an oriented area as, for instance, #"....."@. Of course, these new boundaries must be absent from the present contents of the file !
So, assuming the original text :
1:23:"This:is a: small"text:to :see"if :my :logic:"is: correct:"I: hope:that": all: will:be"::fine,: indeed": ! :":"78:9
The simple S/R :
SEARCH ".*?"
REPLACE #$0@
would get the following text :
1:23:#"This:is a: small"@text:to :see#"if :my :logic:"@is: correct:#"I: hope:that"@: all: will:be#"::fine,: indeed"@: ! :#":"@78:9
Accordingly, the correct regex becomes :
SEARCH :(?=[^#\r\n]*@)
REPLACE Any string or character, even EMPTY
Again, only the colons, inside the areas, which are underlined, are matched by the regex !
1:23:#"This:is a: small"@text:to :see#"if :my :logic:"@is: correct:#"I: hope:that"@: all: will:be#"::fine,: indeed"@: ! :#":"@78:9
¯ ¯ ¯ ¯ ¯ ¯ ¯ ¯¯ ¯ ¯
To end with, use the simple regex :
SEARCH #|@
REPLACE Empty
in order to get the original areas "....."
Et voilà !
Cheers,
guy038