Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8224451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:04:35+00:00 2026-06-07T15:04:35+00:00

The typical use-case is when a regex needs to include user input. Characters with

  • 0

The typical use-case is when a regex needs to include user input. Characters with special meaning in regex (i.e. “the dirty dozen” in Perl) need to be escaped. Perl provides the “quotemeta” functionality to do this: simply encapsulate interpolating variables in \Q and \E. But Tcl provides no such functionality (and according to this page, even with ARE).

Is there a good (rigorous) implementation of quotemeta in Tcl out there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:04:37+00:00Added an answer on June 7, 2026 at 3:04 pm

    Perl’s quotemeta function simply replaces every non-word character (i.e., characters other than the 26 lowercase letters, the 26 uppercase letters, the 10 digits, and underscore) with a backslash. This is overkill, since not all non-word characters are regexp metacharacters, but it’s simple and safe, since escaping a non-word character that doesn’t need escaping is harmless.

    I believe this implementation is correct:

    proc quotemeta {str} {
        regsub -all -- {[^a-zA-Z0-9_]} $str {\\&} str
        return $str
    }
    

    But thanks to glenn’s comment, this one is better, at least for modern versions of Tcl (\W matches any non-word character starting some time after Tcl 8.0.5):

    proc quotemeta {str} {
        regsub -all -- {\W} $str {\\&} str
        return $str
    }
    

    (I’m assuming that Tcl’s regular expressions are similar enough to Perl’s so that this will do the same job in Tcl that it does in Perl.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The use case I can think of is the following: In a typical application,
Background My typical use case: # Table id category dataUID --------------------------- 0 A (NULL)
I am using jQuery dialog in a simple, typical use case: In the Javascript:
My iPhone programs frequently contain grouped table views. A typical use might be for
Typical jQuery over-use: $('button').click(function() { alert('Button clicked: ' + $(this).attr('id')); }); Which can be
I am making a registration system with an e-mail verifier. Your typical use this
A typical use of bitfield is to declare a space efficient variable smaller than
On a typical Ubuntu (10.4 in this case) desktop how can I do to
For typical 3-tiered application, I have seen that in many cases they use a
Consider a typical relational structure: Answer has many comments. comments belongs to a user,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.