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 74387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:21:01+00:00 2026-05-10T20:21:01+00:00

I’m having a hard time determining what characters must be escaped when using Perl’s

  • 0

I’m having a hard time determining what characters must be escaped when using Perl’s qr{} construct

I’m attempting to create a multi-line precompiled regex for text that contains a myriad of normally escaped characters (#*.>:[]) and also contains another precompiled regex. Additionally I need to match as strictly as possible for testing purposes.

my $output = q{# using defaults found in .config * * Options:   1. opt1 > 2. opt2 choice[1-2?]: };  my $sc = qr{(>|\s)}smx; my $re = qr{# using defaults found in .config * * Options: $sc 1. opt1 $sc 2. opt2 choice[1-2?]: }mx;  if ( $output =~ $re ) {   print 'OK!\n'; } else {   print 'D'oh!\n'; } 

Error:

Quantifier follows nothing in regex; marked by <-- HERE in m/# using defaults found in .config * <-- HERE  * Options: (?msx-i:(>|\s)) 1. opt1 (?msx-i:(>|\s)) 2. opt2 choice[1-2?]: / at ./so.pl line 14. 

Attempting to escape the asterisks results in a failed match (D’oh output). Attempting to escape other pesky chars also results in a failed match. I could continue trying different combos of what to escape, but there’s a lot of variations here and am hoping someone could provide some insight.

  • 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. 2026-05-10T20:21:02+00:00Added an answer on May 10, 2026 at 8:21 pm

    You have to escape the delimiter for qr//, and you have to escape any regex metacharacters that you want to use as literals. If you want those to be literal *’s, you need to escape them since the * is a regex quantifier.

    Your problem here is the various regex flags that you’ve added. The /m doesn’t do anything because you don’t use the beginning- or end-of-string anchors (^, $). The /s doesn’t do anything because you don’t use the wildcard . metacharacter. The /x makes all of the whitespace in your regex meaningless, and it turns that line with the # into a regex comment.

    This is what you want, with regex flags removed and the proper things escaped:

    my $sc = qr{(>|\s)};  my $re = qr{# using defaults found in \.config \* \* Options: $sc 1\. opt1 $sc 2\. opt2 choice\[1-2\?]: }; 

    Although Damian Conway tells people in Perl Best Practices to always put these options on their regexes, you now see why he’s wrong. You should only add them when you want what they do, and you should only add things when you know what they do. 🙂 Here’s what you might do if you want to use /x. You have to escape any literal whitespace, you need to denote the line endings somehow, and you have to escape the literal # character. What was readable before is now a mess:

     my $sc  = qr{(>|\s)}; my $eol = qr{[\r\n]+};  my $re  = qr{\# \s+ using \s+ defaults \s+ found \s+ in \s+ \.config $eol \*                    $eol \*                    $eol Options:              $eol $sc \s+ 1\. \s+ opt1   $eol $sc \s+ 2\. \s+ opt2   $eol choice\[1-2\?]: \s+ }x;  if ( $output =~ $re ) {   print 'OK!\n'; } else {   print 'D'oh!\n'; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer That's a good question. I would call that a double… May 11, 2026 at 1:03 pm
  • added an answer It's not clear whether you want to make this an… May 11, 2026 at 1:03 pm
  • added an answer Never mind. It appears to be part of the core… May 11, 2026 at 1:03 pm

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.