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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:23:43+00:00 2026-06-11T19:23:43+00:00

I have five different regular expressions with common parts. All parts with ? at

  • 0

I have five different regular expressions with common parts. All parts with ? at the end are optional but the order must remain the same. title1–title6 is where the regular expressions differ from each other.

How can I group these in order to eliminate repetition of the common parts?

Pseudo code follows:

title1       type? column option?
title2 name? type? column option?
title3 name? type? column option?
title4 name?       column option?
title5 name?       column other

What I have so far is:

(title1 type?|(title2|title3) name? type?|(title4|title5) name?) column option?

And besides the repetitions I can’t figure out what’s the best way to add other part for the last regular expression.

EDIT

I decided to stick to my initial plan to have all regular expressions separate because of the amount of the variables that I have to extract from them.
In case anyone is curious what my solution is:

var blocks = {
  name1: /regex1/,
  name2: /regex2/,
  name3: /regex3/,
  ...
};

var regex = [
  createRegex(['name1', 'name2', 'name3', ...]),
  createRegex(['name1', 'name3', 'name4', ...]),
  ...
];

function createRegex = function (params) {
  var regex = '';
  for (var i=0; i < params.length; i++) {
    var name = params[i];
    regex += blocks[name].source;
  }
  return new RegExp(regex, 'i');
}

This is how I initialize the list of regular expressions and it’s not a pseudo code (except for the regexes and their names).

  • 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-11T19:23:44+00:00Added an answer on June 11, 2026 at 7:23 pm

    I would use this expression, only a few of the expressions have common parts.

    ^((title1\s+(type\s)?column(\soption)?)|((title2|title3) (name\s)?(type\s)?column(\soption)?)|(title4(\sname)?\s+column(\soption)?)|(title5(\sname)?\s+column other))$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have five tables that are fairly similar in structure but different enough that
I have two xml files which have the same data but different names for
in my C project I have five different function (with the same name) which
I have five combo boxes. Each one has a different name, but the possible
I have Five check boxes Search All Template 1 Template 2 Template 3 Template
I have five consumers and one producer. The five consumers each output different data,
I have a table with a list of names spread across five different columns.
Ok I have four parameters in the url xxx.html?p1=something&p2=else&p3=here&p4=too And I have five different
I have five fields for number input, and each of these fields must be
I have a user_info table in five different locations. Now I need to integrate

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.