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

  • Home
  • SEARCH
  • 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 340863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:39:20+00:00 2026-05-12T10:39:20+00:00

Consider a string that looks like this: RR1 S5 C92 This a rural route

  • 0

Consider a string that looks like this:

RR1 S5 C92

This a rural route address for out-of-town mail delivery: Rural Route, Site, Compartment. Each letter is followed by a number and a space. Usually one to three digits long, but you never know how many numbers it could be! If the user is lazy, they may have entered zero, one or many spaces.

Question:
What regex would YOU use to determine if a given string matches this pattern?

Its usage would be something like this:

string ruralPattern; //a regex pattern here
bool isRural = Regex.Match(someString, ruralPattern);

Update: Thank you for your suggestions! Performance and usage will be within a static method in an assembly to be called from a web service. The strings being checked against this pattern will be max 50 characters. The method will be called roughly once every 5 seconds. Any suggestions on keeping it static? Much appreciated!

  • 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-12T10:39:21+00:00Added an answer on May 12, 2026 at 10:39 am

    This should work:

    ^[Rr][Rr]\d+ *[Ss]\d+ *[Cc]\d+$
    

    or as per other comment

    ^[Rr][Rr][0-9]+ *[Ss][0-9]+ *[Cc][0-9]+$
    

    What it all means:

    • ^ – start of string
    • [Rr] – next char must be a R or r
    • [Rr] – next char must be a R or r
    • \d+ or [0-9]+ – next part must be 1 or more digits
    • (space)* – allow for 0 or more spaces
    • [Ss] – next char must be a S or s
    • \d+ or [0-9]+ – next part must be 1 or more digits
    • (space)* – allow for 0 or more spaces
    • [Cc] – next char must be a C or c
    • \d+ or [0-9]+ – next part must be 1 or more digits
    • $ – end of string

    There might be a more elegant solution but this is pretty easy to read.

    Edit: Updated to include input from some of the comments

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

Sidebar

Related Questions

Consider this class: class foo(object): pass The default string representation looks something like this:
Consider the class below that represents a Broker: public class Broker { public string
Consider this: public class TestClass { private String a; private String b; public TestClass()
Consider an algorithm that needs to determine if a string contains any characters outside
Consider this: string test = ""; somestring.ToList().Take(50).Select( delegate(char x) { test += x; return
I have a data set that looks like the below (the input). IR# CR#
Consider this class: case class Person(val firstName: String, val lastName: String, age: Int) val
Consider the following string: ab(cd.xz) e(ab(fg).xz)) ab(hi.xz) I want to match every substring that
Consider the following code snippet private void ProcessFile(string fullPath) { XmlTextReader rdr = new
Consider the 2 following methods of reading a string from a file: NSString *path

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.