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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:40:25+00:00 2026-05-12T16:40:25+00:00

So i have a regex pattern, and I want to generate all the text

  • 0

So i have a regex pattern, and I want to generate all the text permutations that would be allowed from that pattern.

Example:

var pattern = "^My (?:biological|real)? Name is Steve$";
var permutations = getStringPermutations(pattern);

This would return the list of strings below:

My Name is Steve

My real Name is Steve

My biological Name is Steve

Update:
Obviously a regex has an infinate number of matches, so i only want to generate off of optional string literals as in the (?:biological|real)? from my example above. Something like (.)* has too many matches, so I will not be generating them off of that.

  • 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-12T16:40:25+00:00Added an answer on May 12, 2026 at 4:40 pm

    If you restrict yourself to the subset of regular expressions that are anchored at both ends, and involve only literal text, single-character wildcards, and alternation, the matching
    strings should be pretty easy to enumerate. I’d probably rewrite the regex as a BNF grammar
    and use that to generate an exhaustive list of matching strings. For your example:

    <lang>   -> <begin> <middle> <end>
    <begin>  -> "My "
    <middle> -> "" | "real" | "biological"
    <end>    -> " name is Steve"
    

    Start with the productions that have only terminal symbols on the RHS, and enumerate
    all the possible values that the nonterminal on the LHS could take. Then work your
    way up to the productions with nonterminals on the RHS. For concatenation of nonterminal symbols, form the Cartesian product of the sets represented by each RHS nonterminal.
    For alternation, take the union of the sets represented by each option. Continue
    until you’ve worked your way up to <lang>, then you’re done.

    However, once you include the ‘*’ or ‘+’ operators, you have to contend with infinite
    numbers of matching strings. And if you also want to handle advanced features like backreferences…you’re probably well on your way to something that’s isomorphic
    to the Halting Problem!

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

Sidebar

Related Questions

I have a regex pattern that searches for words in a text file. How
I have a regex email pattern and would like to strip all but pattern-matched
I want a regex pattern to allow a mailto: link to have multiple email
I currently have a regex pattern that matches a specific word, which includes arbitrary
I have an word file that contain my specified pattern text {pattern} and I
I have a regex pattern for URL's that I use to check for links
I want to use input from a user as a regex pattern for a
I have the following regex pattern which works fine: #^(.+?)=(.+?)$#D However I want to
I have a regex in Java: Pattern pattern = Pattern.compile(<string>text</string><string>.+</string>); Matcher matcher = pattern.matcher(ganzeDatei);
I have a block of text from which I want to extract the valid

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.