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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:41:42+00:00 2026-06-11T23:41:42+00:00

I need to use regex in C# to split up something like 21A244 where

  • 0

I need to use regex in C# to split up something like “21A244” where

  • The first two numbers can be 1-99
  • The letter can only be 1 letter, A-Z
  • The last three numbers can be 111-999

So I made this match
“([0-9]+)([A-Z])([0-9]+)”

but for some reason when used in C#, the match functions just return the input string. So I tried it in Lua, just to make sure the pattern was correct, and it works just fine there.

Here’s the relevant code:

var m = Regex.Matches( mdl.roomCode, "(\\d+)([A-Z])(\\d+)" );

System.Diagnostics.Debug.Print( "Count: " + m.Count );

And here’s the working Lua code in case you were wondering

local str = "21A244"
print(string.match( str, "(%d+)([A-Z])(%d+)" ))

Thank you for any help

EDIT: Found the solution

var match = Regex.Match(mdl.roomCode, "(\\d+)([A-Z])(\\d+)");
var group = match.Groups;
System.Diagnostics.Debug.Print( "Count: " + group.Count );

System.Diagnostics.Debug.Print("houseID: " + group[1].Value);
System.Diagnostics.Debug.Print("section: " + group[2].Value);
System.Diagnostics.Debug.Print("roomID: " + group[3].Value);
  • 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-11T23:41:43+00:00Added an answer on June 11, 2026 at 11:41 pm

    Firstly you should make your regex a little more specific and limit how many numbers are allowed at the beginning/end. How about:

    ([1-9]{1,2})([A-Z])([1-9]{1,3})

    Next, the results of the captures (i.e. the 3 parts in parens) will be in the Groups property of your regex matcher object. I.e.

    m.Groups[1] // First number
    m.Groups[2] // Letter
    m.Groups[3] // Second number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use JavaScript split but I'm useless at regex so what i
I have two example filename strings: jquery.ui.min.js jquery.ui.min.css What regex can I use to
I need to be able to parse strings like these: kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three -+gdl+-kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three-+gdl+- and
I would like to use the .Net Regex.Split method to split this input string
I need to do use php/regex to replace this: {{image-4-m}} to this: <img src=4.jpg
What is the regex I need to use if I Need to select the
I need a regex to use in Java to replace a String with UNKNOWN
I don't usually use regular expressions, hence my question. I need a regex to
I need use this method with three distinct classes: Orders, Customers, Suppliers public void
So, I need use this event so I can navigate trought blog posts. I

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.