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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:46:03+00:00 2026-06-07T17:46:03+00:00

Here is the code I am using to find transit numbers of the form

  • 0

Here is the code I am using to find transit numbers of the form RB\d{4}, SW\d{4} and S\d{4}:

Regex transitRegex = new Regex("^(RB|SW?)(<?transit>\\d{4}).*");
Match m1 = transitRegex.Match(transitNumber);
if (m1.Success)
{
    Regex transitRegexNoZeroes = new Regex("0+(<?transitNoZeroes>\\d+)");
    Match m2 = transitRegexNoZeroes.Match(m1.Groups["transit"].Value);
    if (m2.Success)
    {
        transitNumber = m2.Groups["transitNoZeroes"].Value.ToString();
        MessageBox.Show(transitNumber, "Transit Number", MessageBoxButtons.OK);
    }
    else
    {
        transitNumber = m1.Groups["transit"].Value.ToString();
    }
}
else
{
    MessageBox.Show("Could not find transit number in " + transitNumber, "Parsing Error", MessageBoxButtons.OK);
}

However I am failing to match any lines. Here is an example of a line that fails:

RB80720C1XX -  Intermittent COMM lOSS ****CHRONIC**** 

For the life of me I can’t figure out what’s wrong with the regex. Any advice is appreciated.

Regards.

EDIT: Inner match edited to allow numbers with leading zeroes to still contain zeroes.

  • 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-07T17:46:06+00:00Added an answer on June 7, 2026 at 5:46 pm

    Your first pattern is a little off. Try this instead:

    @"^(RB|SW?)(?<transit>\d{4})"
    

    Note, the position of the question mark. You can test the pattern here.

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

Sidebar

Related Questions

Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
Here is my code i am using for custom search, <div id=cse-search-form style=width: 100%;>Loading</div>
I've got an error while using find() function. Here is the code: #include <iostream>
I am using a regex pattern to find instances of [code][/code] BB tags. (This
here is a code : using System; using Nemerle.Collections; using Nemerle.Text; //using Nemerle.Utility; using
Here is the my python code using BeautifulSoup. The main issue is with the
I'm using the code here and I want all the functions which call SDL
Alright...I am here looking for some bread crumbs. This is my code: using System;
Ok, here's what I'm trying to do... given this razor code @using(Html.WriteLater()) { output
Here's the code I'm using to make a custom AlertDialog. public void onButtonClicked(View v)

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.