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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:17:28+00:00 2026-05-28T14:17:28+00:00

I wrote a bunch of regular expressions for a C# (3.5) ASP.NET web application.

  • 0

I wrote a bunch of regular expressions for a C# (3.5) ASP.NET web application. I am not an advanced regular expression user by any means. I am troubleshooting one that has me totally confused to as why it is not working. Especially since I have similar ones that are working fine.

Here are the details. Thank you for your time and kind assistance.

What my application does is takes 2 individual values. If the 2 values together match a predefined set of rules, then they get mapped to a certain value.

I have defined some of the rules as such (note: these are just made up by me and have no programming significance or meaning):

Element 1: Cxxxx*####

Element 2: Czzzz*####

For Element 1:
What this means is that this sequence has to start with “C”. The next 4 characters (the four X’s) are alphanumeric. The asterisk means it can be (“R” or “D”). The # symbols mean it can be a sequence of any 4 alphanumeric characters.

For Element 2:
What this means is that this sequence has to start with “C”. The next 4 characters (the four Z’s) are alphanumeric. The asterisk means it can be (“R” or “D”). The # symbols mean it can be a sequence of any 4 alphanumeric characters.

Between the two elements, the X’s and the Z’s simply mean that the 4 character sequence cannot be the same. It must be unique between the two.

So these two elements violate the rule since the “1491” repeats in the same spot in the sequence.

Element 1: C1491D1234

Element 2: C1491D5678

This one would return true as it should be fine given the rules of the sequence:

Element 1: C1491D1234

Element 2: C1599D5678

This one would return true as it should be fine given the rules of the sequence:

Element 1: C1491D1234

Element 2: C1599D1234

This is the regular expression I am using to create this rule:

C([A-Za-z0-9]{4})[DdRr][A-Za-z0-9]{4}-C(?!\1)[DdRr][A-Za-z0-9]{4}

These are the two elements I am using to test the condition:

Element 1: C1491D1491

Element 2: C1000R4100

For some reason, my regular expression is wrong and is not returning true.

This is how my C# program sees the sequence: C1491D1491-C1000R4100

I have been using this website to test:

http://regexhero.net/tester/

  • 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-28T14:17:28+00:00Added an answer on May 28, 2026 at 2:17 pm

    Your regex has a subtle flaw. The (?!\1) is a negative lookahead: It checks that the first backreference does not repeat, but it does not consume the new sequence. You can fix your code like this:

    @"C([A-Za-z0-9]{4})[DdRr][A-Za-z0-9]{4}-C(?!\1)[A-Za-z0-9]{4}[DdRr][A-Za-z0-9]{4}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an application using ASP.NET MVC, in this application I have an Index
I wrote up this regular expression: p = re.compile(r''' \[\[ #the first [[ [^:]*?
I'm using a web service for passing information from a bunch of old .asp
I have a web page with a bunch of links. I want to write
I wrote a small internal web app using (a subset of) pylons . As
I wrote a bunch of code and i would like to fix it the
I wrote a bunch of code in the .cs file in c# for a
I wrote a bunch of unit tests to cover the windows registry reading/writing. They
I have android application that is written regular way. layouts, java, APK. Now, depending
I wrote a bunch of code in Haskell to create an index of a

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.