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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:10:09+00:00 2026-06-03T17:10:09+00:00

Example text (I’ve highlighted the desired / ‘s): pair[@Key=2] / Items / Item[Person/Name=’Martin’] /

  • 0

Example text (I’ve highlighted the desired /‘s):

pair[@Key=2]/Items/Item[Person/Name=’Martin’]/Date

I’m trying to get each forward slash that isn’t within a square bracket, anyone slick with Regex able to help me on this? The use would be:

string[] result = Regex.Split(text, pattern);

I’ve done it with this code, but was wondering if there was a simpler Regex that would do the same thing:

private string[] Split()
{
    List<string> list = new List<string>();
    int pos = 0, i = 0;
    bool within = false;
    Func<string> add = () => Format.Substring(pos, i - pos);
    //string a;
    for (; i < Format.Length; i++)
    {
        //a = add();
        char c = Format[i];
        switch (c)
        {
            case '/':
                if (!within)
                {
                    list.Add(add());
                    pos = i + 1;
                }
                break;
            case '[':
                within = true;
                break;
            case ']':
                within = false;
                break;
        }
    }
    list.Add(add());
    return list.Where(s => !string.IsNullOrEmpty(s)).ToArray();
}
  • 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-03T17:10:11+00:00Added an answer on June 3, 2026 at 5:10 pm

    using Regex.Matches might be a better approach than trying to use split. Instead of specifying a pattern to split on, you try to match your desired outputs. This works in basic cases:

    string[] FancySplit(string input) {
        return Regex.Matches(input, @"([^/\[\]]|\[[^]]*\])+")
            .Cast<Match>()
            .Select(m => m.Value)
            .ToArray();
    }
    

    The approach of the regular expression is to look for a sequence of:

    • characters that are not [, ], or /

      or
    • A sequence of the form [ something ], where something is allowed to contain /
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for example : I want to remove all highlighted tags alt text http://shup.com/Shup/299976/110220132930-My-Desktop.png
here is my example text ------=_Part_564200_22135560.1319730112436 Content-Type: text/plain; charset=utf-8; name=text_0.txt Content-Transfer-Encoding: 7bit Content-ID: <314>
I am trying to replace multiple variables in a text. I have For example
I need to create an activity(view) that shows several lists, for example: (text)Fruits: (item)apple
I'm trying to join all lines who do not have a match example text:
I am using network stream to send a file name (example :text.txt) and then
Can anybody help me with retrieving some elements from the following example text: sdfaasdflj
<div class=example>Some example text</div> <div class=example>Some more example text</div> How can I remove all
I have a string for example like :)text :)text:) :-) word :-( i need
On mac os console, when doing paste of large quantities of text (for example

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.