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 \ Q and \ E .

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:

  proc quetamata {str} {regsub -all - {[a-zA-Z0-9_]} $ Str {\\ & amp;} Str Return $ str}   

But thanks to Glen's comment, this is the best, at least the TCL ( \ w

  proc quotemeta {str} {regsub -all - {\ W] } $ Str {\\ & amp;} str returns $ str}   

(I'm assuming that on TCL's regular expressions Same same goal, so it will work the same in Perk.)

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -