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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:38:38+00:00 2026-06-12T02:38:38+00:00

I need to separate strings with semicolon ( ; ) as delimiter. The semicolon

  • 0

I need to separate strings with semicolon (;) as delimiter. The semicolon inside parenthesis should be ignored.

Example:

string inputString = "(Apple;Mango);(Tiger;Horse);Ant;Frog;";

The output list of strings should be:

(Apple;Mango)
(Tiger;Horse)
Ant
Frog

The other valid input strings can be :

string inputString = "The fruits are (mango;apple), and they are good"

The above string should split to a single string

"The fruits are (mango;apple), and they are good"

string inputString = "The animals in (African (Lion;Elephant) and Asian(Panda; Tiger)) are endangered species; Some plants are endangered too."

The above string should split to two strings as shown below:

"The animals in (African (Lion;Elephant) and Asian(Panda; Tiger)) are endangered species"
"Some plants are endangered too."

I searched a lot but could not find the answer to the above scenario.

Does anybody know how to achieve this without reinventing the wheel?

  • 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-12T02:38:40+00:00Added an answer on June 12, 2026 at 2:38 am

    Use a regular expression that matches what you want to keep, not the separators:

    string inputString = "(Apple;Mango);(Tiger;Horse);Ant;Frog;";
    
    MatchCollection m = Regex.Matches(inputString, @"\([^;)]*(;[^;)]*)*\)|[^;]+");
    
    foreach (Match x in m){
      Console.WriteLine(x.Value);
    }
    

    Output:

    (Apple;Mango)
    (Tiger;Horse)
    Ant
    Frog
    

    Expression comments:

    \(           opening parenthesis
    [^;)]*       characters before semicolon
    (;[^;)]*)*   optional semicolon and characters after it
    \)           closing parenthesis
    |            or
    [^;]+        text with no semicolon
    

    Note: The expression above also accepts values in parentheses without a semicolon, e.g. (Lark) and mulitple semicolons, e.g. (Lark;Pine;Birch). It will also skips empty values, e.g. ";;Pine;;;;Birch;;;" will be two items, not ten.

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

Sidebar

Related Questions

I have for example this string: iCanSeeBluePeople and I need it to separate it
Trying to split this string 主楼怎么走 into separate characters (I need an array) using
I have following strings. But I need to separate them by this jsonp1343930692 and
I need to a) separate strings from numbers for a selection of cells and
Detecting a parenthesis pattern in a string This is a line (an example between
If there are two separate strings, we need to retrieve all words that are
I need to encode some strings to add to a URL. My string contains
I need to parse and separate input strings using VB.NET. Split method works in
I have several strings of the format AA11 AAAAAA1111111 AA1111111 I need to separate
I need to split this kind of strings to separate the email between less

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.