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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:53:22+00:00 2026-05-20T14:53:22+00:00

I need a rule that regex or similar that can be used to parse

  • 0

I need a rule that regex or similar that can be used to parse any given input string containing space delimited words to create a usually longer output string where certain parts get expanded according to certain conditions. I could create code to do this from scratch but I was wondering if I might not need to as this would be not a trivial as it may seem.

In the following example I will use ‘a b c etc…’ to represent words, this could just as easily be ‘cake 14 h etc…’ for example however ‘a b c etc…’ are easier to use to describe how the rule should work. I also use the special characters {, }, [, | and ]. In doing so I am not refering to regex meanings these characters may have.

I’m also going to include line breaks that shouldn’t exist in the examples to make things more readable.

The rule would specify that everything inside {} enclosures that occur in the input string wouldn’t appear as is in the output string. The contents of a {} would instead occur in the same place but repeated a number of times defined by it’s [] enclosures.

1.

Note that ‘b’ and ‘c’ are separated with ‘|’.

{a [b | c]}

should become:

a b
a c

2.

Note that ‘b’ and ‘c’ are together and separate from ‘d’. The {} enclosure contains two []’s, The first containing two elements and the 2nd with 3 elements making 6 in total.

{[a b | c][d | e | f]}

should become:

a b d
a b e
a b f
c d
c e
c f

3.

And now for a more involved example.

{a [b c | d] e f [g | h | i]} j

should become:

a b c e f g
a b c e f h
a b c e f i
a d e f g
a d e f h
a d e f i
j

without the line breaks such that it should read:

a b c e f g a b c e f h a b c e f i a d e f g a d e f h a d e f i j

Here are two more concrete examples from DR Seuss with line breaks added to make things easier to read, the 2nd example is edited significantly from the original text:

input:

{I do not like [them in a box | them with a fox | them in a house
| them with a mouse | them here or there | them anywhere | green
eggs and ham | them, Sam-I-am].}

output:

I do not like them in a box.
I do not like them with a fox.
I do not like them in a house.
I do mot like them with a mouse.
I do not like them here or there.
I do not like them anywhere.
I do not like green eggs and ham.
I do not like them, Sam-I-am.

input:

{[Would | could] you} ? {Would you [like | eat] them
[in a house | with a mouse]?}

output:

Would you, could you?

Would you like them in a house?
Would you like them with a mouse?

Would you eat them in a house?
Would you eat them with a mouse?

Ideally the {} enclosures should be able to stack. None of these examples have shown stacking {} enclosures.

I can already reference individual words from their number (1st, 2nd etc…) or other label, this is easier than for example looking up individual letters some offset into the whole input due to how I am storing the text.

  • 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-20T14:53:22+00:00Added an answer on May 20, 2026 at 2:53 pm

    Regex is probbably not helpfull, others may be helpfull but most of the work would still need to be done yourself.

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

Sidebar

Related Questions

I need to build a rule-based system that can be run and developed in
Need a makefile dependency rule that can handle missing files gives some pointers on
I'm struggling with a css selector. I need a css rule that returns all
I need to add a rule in the firewall so that my self-hosted http
Do I even need this rule anymore? I don't see any requests incoming for
I can never remember the number. I need a memory rule.
I need to write a rule to redirect any image file to a specific
One rule that I need is that if the last vowel (aeiou) of a
I need a rewrite rule that will do an internal redirect from: <domain>/directory/<anything>/<anything>.php to:
I am trying to write a Make rule that says, roughly, If you need

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.