regex - Implementing "quotemeta" \Q ... \E in Tcl? -
Typical Usage-case occurs when a regex needs to include user input Regards (I.e. "Dirty Dozen" in Perl) is needed to escape. Pearl provides the functionality of "quotemeta" to do this: simply assign the variable to Does TCL have a good (strict) implementation in the coatetta? The work of Pearl changes only every non-word character (i.e., letters other than 26 lowercase letters, 26 uppercase letters, 10 digits and underscores). A backslash is a redundancy because all non-word characters are not regexp metacharacters, but it is simple and safe, because to avoid a non-word character that is not required to escape, is harmless. I believe this implementation is correct: But thanks to Glen's comment, this is the best, at least the TCL ( (I'm assuming that on TCL's regular expressions Same same goal, so it will work the same in Perk.) \ Q and
\ E .
proc quetamata {str} {regsub -all - {[a-zA-Z0-9_]} $ Str {\\ & amp;} Str Return $ str}
\ w
proc quotemeta {str} {regsub -all - {\ W] } $ Str {\\ & amp;} str returns $ str}
Comments
Post a Comment