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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:55:58+00:00 2026-05-30T15:55:58+00:00

I made an article spinner that used regex to find words in this syntax:

  • 0

I made an article spinner that used regex to find words in this syntax:

{word1|word2}

And then split them up at the “|”, but I need a way to make it support tier 2 brackets, such as:

{{word1|word2}|{word3|word4}}

What my code does when presented with such a line, is take “{{word1|word2}” and “{word3|word4}”, and this is not as intended.

What I want is when presented with such a line, my code breaks it up as “{word1|word2}|{word3|word4}”, so that I can use this with the original function and break it into the actual words.

I am using c#.

Here is the pseudo code of how it might look like:

Check string for regex match to "{{word1|word2}|{word3|word4}}" pattern
If found, store each one as "{word1|word2}|{word3|word4}" in MatchCollection (mc1)
Split the word at the "|" but not the one inside the brackets, and select a random one (aka, "{word1|word2}" or "{word3|word4}")
Store the new results aka "{word1|word2}" and "{word3|word4}" in a new MatchCollection (mc2)
Now search the string again, this time looking for "{word1|word2}" only and ignore the double "{{" "}}"
Store these in mc2.
I can not split these up normally

Here is the regex I use to search for “{word1|word2}”:

Regex regexObj = new Regex(@"\{.*?\}", RegexOptions.Singleline);
MatchCollection m = regexObj.Matches(originalText); //How I store them

Hopefully someone can help, thanks!

Edit: I solved this using a recursive method. I was building an article spinner btw.

  • 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-30T15:55:59+00:00Added an answer on May 30, 2026 at 3:55 pm

    That is not parsable using a regular expression, instead you have to use a recursive descent parser. Map it to JSON by replacing:

    1. { with [
    2. | with ,
    3. wordX with "wordX" (regex \w+)

    Then your input

    {{word1|word2}|{word3|word4}}
    

    becomes valid JSON

    [["word1","word2"],["word3","word4"]]
    

    and will map directly to PHP arrays when you call json_decode.

    In C#, the same should be possible with JavaScriptSerializer.

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

Sidebar

Related Questions

After reading this article I made a point that int () yields 0 because
This article seems to suggest that there such things as include templates. I've made
I'm building a Symfony application that's made to run many sites. Similar to this
In this MSDN article , it says that In the .NET Framework version 2.0,
I just ran across this an Google App Engine article that uses that funny
I have made some code which exports some details of a journal article to
I have a sketch pad made in Flash AS3 like this one here: http://henryjones.us/articles/using-the-as3-jpeg-encoder
Made this nice little loop for hiding and showing div's, works as a charm
I made a Java Applet with some Standard GUI Components on it. I used
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }

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.