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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:31:40+00:00 2026-05-27T23:31:40+00:00

Guys I hate Regex and I suck at writing. I have a string that

  • 0

Guys I hate Regex and I suck at writing.

I have a string that is space separated and contains several codes that I need to pull out. Each code is marked by beginning with a capital letter and ending with a number. The code is only two digits.

I’m trying to create an array of strings from the initial string and I can’t get the regular expression right.

Here is what I have

String[] test = Regex.Split(originalText, "([a-zA-Z0-9]{2})");

I also tried:

String[] test = Regex.Split(originalText, "([A-Z]{1}[0-9]{1})");

I don’t have any experience with Regex as I try to avoid writing them whenever possible.

Anyone have any suggestions?

Example input:

AA2410 F7 A4 Y7 B7 A 0715 0836 E0.M80

I need to pull out F7, A4, B7. E0 should be ignored.

  • 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-27T23:31:40+00:00Added an answer on May 27, 2026 at 11:31 pm

    You want to collect the results, not split on them, right?

    Regex regexObj = new Regex(@"\b[A-Z][0-9]\b");
    allMatchResults = regexObj.Matches(subjectString);
    

    should do this. The \bs are word boundaries, making sure that only entire strings (like A1) are extracted, not substrings (like the A1 in TWA101).

    If you also need to exclude “words” with non-word characters in them (like E0.M80 in your comment), you need to define your own word boundary, for example:

    Regex regexObj = new Regex(@"(?<=^|\s)[A-Z][0-9](?=\s|$)");
    

    Now A1 only matches when surrounded by whitespace (or start/end-of-string positions).

    Explanation:

    (?<=  # Assert that we can match the following before the current position:
     ^    # Start of string
    |     # or
     \s   # whitespace.
    ) 
    [A-Z] # Match an uppercase ASCII letter
    [0-9] # Match an ASCII digit
    (?=   # Assert that we can match the following after the current position:
     \s   # Whitespace
    |     # or
     $    # end of string.
    )
    

    If you also need to find non-ASCII letters/digits, you can use

    \p{Lu}\p{N}
    

    instead of [A-Z][0-9]. This finds all uppercase Unicode letters and Unicode digits (like Ä٣), but I guess that’s not really what you’re after, is it?

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

Sidebar

Related Questions

Sorry guys, I hate asking dumb questions but I have seriously been searching for
I hate writing error condition code. I guess I don't have a good approach
Guys, I’ve been writing code for 15+ years, but managed to avoid Web Development
guys i have arrays in which i have to match this kind of text
Guys, I HAVE tried reading tons of stuff about EJB. And I don't get
Guys; How are you doing today? I have to create a dll project on
I know you guys hate helping with homework, but I thought I might ask
I hate to ask but I had to. I have an html code. For
I hate to ask here but I am stumped and so were the guys
I have about 4 or 5 different queries that are all exactly like with

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.