Hi, @alan-kilborn,
Regarding the regex syntax 1{2, this is considered as a pure literal expression, which correctly matches the 1{2 string
But if you want to match the literal string 1{2}, as this syntax has the regex meaning : “two consecutive digits” 1, we need to escape the opening brace, {, only ( so 1\{2}1\{2} ) to get a literal expression !
As defined here
All characters are treated as literals, except for characters $, \, (, ), ?, and :
If you want to write the $ ? and the : characters, literally, you do not need, most of the time, to escape them because they are usually found outside their meaning context !
However, the three characters (, ) and \ must always be escaped, in the replacement zone, in order to be written literally !
Parentheses are normally used for lexical grouping in conditional expressions, with these syntaxes :
(?DigitTrue_Exp) or (?{Digit}True_Exp) or (?NameTrue_Exp)
(?DigitTrue_Exp:False_Exp) or (?{Digit}True_Exp:False_Exp) or (?NameTrue_Exp:False_Exp)
Apart from these cases, these two parentheses seem to just represent a pure empty string !
For instance :
SEARCH DEF
REPLACE 123(456 or REPLACE 123()456
would change the string ABCDEFGHI into ABC123456GHI
And the S/R :
SEARCH : DEF
REPLACE : 123( (((XYZ)OP(QRS)TUV ()) )789
would change the string "ABCDEFGHI" into "ABC123 XYZOPQRSTUV 789GHI"
Thus, the S/R :
SEARCH DEF
REPLACE ()
would change the string ABCDEFGHI into ABCGHI ! In other words, the () syntax, in the replacement zone, seems to be a synonym of an empty string ;-)
However, note that :
SEARCH DEF
REPLACE 123)456 or REPLACE 123)456(789
would change the string ABCDEFGHI into ABC123GHI only !
Now, placing some replacement meta-characters, inside parentheses, does not make them literal and they keep these normal behavior :
For instance, the regex S/R :
SEARCH (DEF)|XYZ
REPLACE ---(123(?1TRUE:FALSE)456\\789)---
would change the string ABCDEFGHI ABCXYZGHI into ABC---123TRUE456\789---GHI ABC---123FALSE456\789---GHI
Finally, the only practical application I found of using parentheses, is when you want to delimit a string beginning and/or ending with space characters !
Best Regards,
guy038