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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:21:16+00:00 2026-05-19T03:21:16+00:00

OK my regex is a bit rusty and I’ve been struggling with this particular

  • 0

OK my regex is a bit rusty and I’ve been struggling with this particular problem…

I need to split and process a string containing any number of the following, in any order:

  • Chars (lowercase letters only)
  • Quote delimited strings
  • Ints

The strings are pretty weird (I don’t have control over them). When there’s more than one number in a row in the string they’re seperated by a comma. They need to be processed in the same order that they appeared in the original string.

For example, a string might look like:

abc20a"Hi""OK"100,20b

With this particular string the resulting call stack would look a bit like:

ProcessLetters( new[] { 'a', 'b', 'c' } );
ProcessInts( 20 );
ProcessLetters( 'a' );
ProcessStrings( new[] { "Hi", "OK" } );
ProcessInts( new[] { 100, 20 } );
ProcessLetters( 'b' );

What I could do is treat it a bit like CSV, where you build tokens by processing the characters one at a time, but I think it could be more easily done with a regex?

  • 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-19T03:21:17+00:00Added an answer on May 19, 2026 at 3:21 am

    You can use the pattern contained in this string:

    @"(""[^""]*""|[a-z]|\d+)"
    

    to tokenize the input string you provided. This pattern captures three things: simple quoted strings (no embeded quotes), lower-case characters, and one or more digits.

    If your quoted strings can have escaped quotes within them (e.g., "Hi\"There\"""OK""Pilgrim") then you can use this pattern to capture and tokenize them along with the rest of the input string:

    @"((?:""[^""\\]*(?:\\.[^""\\]*)*"")|[a-z]|\d+)"
    

    Here’s an example:

    MatchCollection matches = Regex.Matches(@"abc20a""Hi\""There\""""""OK""""Pilgrim""100,20b", @"((?:""[^""\\]*(?:\\.[^""\\]*)*"")|[a-z]|\d+)");
    
    foreach (Match match in matches)
    {
        Console.WriteLine(match.Value);
    }
    

    Returns the string tokens:

    a
    b
    c
    20
    a
    "Hi\"There\""
    "OK"
    "Pilgrim"
    100
    20
    b
    

    One of the nice thing about this approach is you can just check the first character to see what stack you need to put your elements in. If the first character is alpha, then it goes into the ProcessLetters stack, if the character is numeric, then it goes into ProcessInts. If the first character is a quote, then it goes into ProcessStrings after trimming the leading and trailing quotes and calling Regex.Unescape() to unescape the embedded quotes.

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

Sidebar

Related Questions

Any regex gurus around here? its driving me crazy. Say I have this string:
I am trying to find some text RegEx /\w*http:[/][/]bit.ly[/]\w*/ig that will find this string
I'm a bit rusty on my regex and javascript. I have the following string
I'm a bit rusty on my regexp and Javascript. I have the following string
I've got this bit of jQuery with some javascript and RegEx mixed in: $(function()
I am brand new to using RegEx's and need a bit of a jump
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
My regex skills are a bit rusty. Can someone provide a expression that I
I'm struggling with the regular expression syntax needed to simply transform this string: posts/2012-03-16-23-07_an-awesome-post.md
I've run into a bit of a problem with a Regex I'm using for

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.