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

  • SEARCH
  • Home
  • 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 6811365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:19:06+00:00 2026-05-26T20:19:06+00:00

I have a list of regular expressions (about 10 – 15) that I needed

  • 0

I have a list of regular expressions (about 10 – 15) that I needed to match against some text. Matching them one by one in a loop is too slow. But instead of writing up my own state machine to match all the regexes at once, I am trying to | the individual regexes and let perl do the work. The problem is that how do I know which of the alternatives matched?

This question addresses the case where there are no capturing groups inside each individual regex. (which portion is matched by regex?) What if there are capturing groups inside each regexes?

So with the following,

/^(A(\d+))|(B(\d+))|(C(\d+))$/

and the string “A123”, how can I both know that A123 matched and extract “123”?

  • 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-05-26T20:19:07+00:00Added an answer on May 26, 2026 at 8:19 pm

    You don’t need to code up your own state machine to combine regexes. Look into Regexp:Assemble. It has methods that’ll track which of your initial patterns matched.

    Edit:

    use strict;
    use warnings;
    
    use 5.012;
    
    use Regexp::Assemble;
    
    my $string = 'A123';
    
    my $re = Regexp::Assemble->new(track => 1);
    for my $pattern (qw/ A(\d+) B(\d+) C(\d+) /) {
      $re->add($pattern);
    }
    
    say $re->re; ### (?-xism:(?:A(\d+)(?{0})|B(\d+)(?{2})|C(\d+)(?{1})))
    say for $re->match($string); ### A(\d+)
    say for $re->capture; ### 123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of regular expressions and I would like to match with
I have been thinking about a regular expression that can transform a list like
i have list of rows that user select and i want to delete them,
If I have a list of regular expressions, is there an easy way to
I have a long list of regular expressions in an ignore.txt, and another long
I have comma separated list of regular expressions: .{8},[0-9],[^0-9A-Za-z ],[A-Z],[a-z] I have done a
I have a list of regular expressions I want to run over a single
Is it possible to match 2 regular expressions in Python? For instance, I have
I have the following regular expression, and i need some advice about it. I
I am attempting to fix some bilingual xml files using regular expressions to match

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.