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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:14:50+00:00 2026-05-26T15:14:50+00:00

I have a string which is formatted like this: $20,$40,$AA,$FF. Basically, hex numbers and

  • 0

I have a string which is formatted like this: $20,$40,$AA,$FF. Basically, hex numbers and they can be of many bytes. I want to check if a string is in the above format, so I tried something like this:

        string a = "$20,$30,$40";

        Regex reg = new Regex(@"$[0-9a-fA-F],");
        if (a.StartsWith(string.Format("{0}{1}", reg, reg)))
            MessageBox.Show("A");

It doesn’t seem to work though, is there anything I’m missing?

  • 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-26T15:14:51+00:00Added an answer on May 26, 2026 at 3:14 pm

    There are 3 things that need to be changed:

    Need to escape your $ symbol as it represents end of line.

    \$
    

    Need to tweak your regex pattern to match the entire string instead of parts.

    ^(\$[0-9a-fA-F]{2},+)+\$[0-9a-fA-F]{2}$
    

    Need to change your code to use Regex.IsMatch.

    string a = "$20,$30,$40"; 
    if (Regex.IsMatch(a,@"^(\$[0-9a-fA-F]{2},+)+\$[0-9a-fA-F]{2}$",RegexOptions.IgnoreCase))
            MessageBox.Show("A");
    

    PS:

    If the input string has white space like a tab or a space in between, then this regex will need to be modified. In such cases, you have to use “\s” at the right positions. For example, if you have white space around the commas like

    string a = "$20 ,$30, $40";
    

    then you need to tweak your RegEx this way:

    ^(\$[0-9a-fA-F]{2}\s*,+\s*)+\$[0-9a-fA-F]{2}\s*$
    

    References:

    1. C# Regex Testers
      • A Better .NET Regular Expression Tester
      • RegexHero tester
    2. about Regex.IsMatch (instead of using Match)
      • MSDN Regex.isMatch
      • Usage example
    3. C# Regular Expression Cheat Sheet

    Old answer below (Ignore):

    Try this:

    "\$[0-9a-fA-F]{2}?[,]{0,1}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table which is full of arbitrarily formatted phone numbers, like this
I have a formatted string from a log file, which looks like: >>> a=test
I have a string which is like this: this is "a test" I'm trying
I have a bignum formatted like a string like this: 123456789123456789123456789 and I need
I’ve got a long string object which has been formatted like this myString =
So I have a flashobject which I need to pass a formatted DateTime string
I have a String which I would like to modify in some way. For
I have an 8 digit integer which I would like to print formatted like
I'm trying to parse through a string formatted like this, except with more values:
I have a formatted string variable to which passing to a ViewData Variable. My

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.