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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:15:02+00:00 2026-06-17T11:15:02+00:00

First up, I’m a N00b with Regex it’s like a new language that I’m

  • 0

First up, I’m a N00b with Regex it’s like a new language that I’m struggling with ATM and looking for some direction.

I have a form that has a serial number field but the fields contents can be one of 3 possible rules.

Rule1 : Length is always 13 Position 1 is always C Positions 2-5 is
numeric Position 6 is alpha Position 7-13 is numeric

Rule2 : Length is 8 or 9 Position 1-2 is alpha Position 3-8 is numeric
Postion 9 is alpha

Rule3 : Length is 9 Position 1-9 is numeric

My question: is this of formula achievable inside regex – and sub question: Pointers for where I can look to or expressions I can decipher ?

Apologies if this is too n00b’esque – RegEx does my head in 🙂

  • 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-17T11:15:05+00:00Added an answer on June 17, 2026 at 11:15 am

    Have a try with:

    /^(C\d{4}[a-zA-Z]\d{7}|[a-zA-Z]{2}\d{6}[a-zA-Z]?|\d{9})$/
    

    I suppose that the last alpha is optional in the rule #2

    explanation:

    The regular expression:
    
    (?-imsx:^(C\d{4}[a-zA-Z]\d{7}|[a-zA-Z]{2}\d{6}[a-zA-Z]?|\d{9})$)
    
    matches as follows:
    
    NODE                     EXPLANATION
    ----------------------------------------------------------------------
    (?-imsx:                 group, but do not capture (case-sensitive)
                             (with ^ and $ matching normally) (with . not
                             matching \n) (matching whitespace and #
                             normally):
    ----------------------------------------------------------------------
      ^                        the beginning of the string
    ----------------------------------------------------------------------
      (                        group and capture to \1:
    ----------------------------------------------------------------------
        C                        'C'
    ----------------------------------------------------------------------
        \d{4}                    digits (0-9) (4 times)
    ----------------------------------------------------------------------
        [a-zA-Z]                 any character of: 'a' to 'z', 'A' to 'Z'
    ----------------------------------------------------------------------
        \d{7}                    digits (0-9) (7 times)
    ----------------------------------------------------------------------
       |                        OR
    ----------------------------------------------------------------------
        [a-zA-Z]{2}              any character of: 'a' to 'z', 'A' to 'Z'
                                 (2 times)
    ----------------------------------------------------------------------
        \d{6}                    digits (0-9) (6 times)
    ----------------------------------------------------------------------
        [a-zA-Z]?                any character of: 'a' to 'z', 'A' to 'Z'
                                 (optional (matching the most amount
                                 possible))
    ----------------------------------------------------------------------
       |                        OR
    ----------------------------------------------------------------------
        \d{9}                    digits (0-9) (9 times)
    ----------------------------------------------------------------------
      )                        end of \1
    ----------------------------------------------------------------------
      $                        before an optional \n, and the end of the
                               string
    ----------------------------------------------------------------------
    )                        end of grouping
    ----------------------------------------------------------------------
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background, I have a python script that will be called periodically by
First of all, let me state that I am very new to Bash scripting.
First I want to say you that I'm totally new in Xcode so I'm
First I have this. <form method=post action=<? echo $_SERVER['PHP_SELF']; ?>> <input type=text name=varenummer id=varenummer
First of all I have to admit that these are very basic and primitive
First of all, I'm using ARC. If I have a class that, for example,
First off, I am a totally new developer with regards to Node.js. I have
First of all I have seen that there are many questions about unrecognized selector
first take a look on this picture from localScope app : i have 2
first of all some details: I configured security as below in web.xml view plaincopy

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.