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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:06:12+00:00 2026-05-17T16:06:12+00:00

When I do this: var m = Regex.Match(aabbccddeeff, [0-9a-fA-F]{6}); I get only aabbcc as

  • 0

When I do this:

var m = Regex.Match("aabbccddeeff", "[0-9a-fA-F]{6}");

I get only aabbcc as result. Actually (using .Matches) there’re two matches: aabbcc and ddeeff.

Why? This causes issues with DataAnnotations.RegularExpressionAttribute because it expects single match that covers whole input value.

How do I write this properly to get a single match?

  • 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-17T16:06:13+00:00Added an answer on May 17, 2026 at 4:06 pm

    What is it that you are trying to achieve here?

    The regular expression provided will try to match a sequence of exactly 6 letters / digits. Since there are 12 consecutive alphanumeric characters in the input, there are 2 consecutive matches. Regex.Match returns the first one, and Regex.Matches both of them, exactly as they should.

    If you want to assert that the entire text will precisely match the regex (since you are using it for input validation, I assume this is the case), so that the entire input string should satisfy Regex.IsMatch, change the expression to:

    ^[0-9a-fA-F]{6}$
    

    On the other hand, if you don’t want matching to be restricted to exactly 6 characters, change it to:

    [0-9a-fA-F]+ 
    

    Or if you are looking to match 12 characters:

    [0-9a-fA-F]{12}
    

    Of course, you might need a ^ and $ around the last 2 expressions too depending on your needs.

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

Sidebar

Related Questions

This one is a real head scratcher for me... var matches = Regex.Matches(<p>test something<script
I'm trying to exclude some data from a string using regex. var match =
Is it possible to do something like this? var pattern = /some regex segment/
How to create regex pattern which is concatenate with variable, something like this: var
I'm confused about the array returned by a regex match when using both /g
This is my function: private IEnumerable<string> SeachItem(int[] ItemIds) { using (var reader = File.OpenText(Application.StartupPath
I was wondering if there is a way having this var string = foo::bar
why does this regex fail to match: (?<=Title = 8:)[^]*(?=) this: ARPHELPTELEPHONE = 8:
I wrote this regex with the idea that it will match any string in
I have code like this: var newMsg = new Msg { Var1 = var1,

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.