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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:13:37+00:00 2026-05-23T07:13:37+00:00

i tried to use Regex in c# , but the following code throws an

  • 0

i tried to use Regex in c# , but the following code throws an exception:

string pattern = "(\d+)([+*/-])(\d+)";

Regex reg = new Regex  (pattern);

After a little dig , i found that in c# if you try to match ‘-‘ with [] expression , it must be put as the first character in that bracket , which confused me.

Could someone jump out and explain that to me ?

Appreciate any of your responses.

  • 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-23T07:13:37+00:00Added an answer on May 23, 2026 at 7:13 am

    The - character takes on a special meaning within a character class [...] to denote a range, so that shorthand expressions like the following work:

    "[a-z]" // matches all lowercase alphabetic characters without having to specify them all.
    

    The - is only interpreted literally if it is the first character simply because it can’t denote a range because no other value precedes it.

    Honestly, it should make no difference whether it is the first or the last character.

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

Sidebar

Related Questions

I'm copletly noob of regex, but i'm forced to use it. I've tried to
I have the following string: $/Mycollection/Branches/Dev/New/php/MySite/src/MySite/somefolder/src/sad.php I need to create regex pattern and take
I have tried to use the following regex expression to remove html whitespace and
I tried to use the following function in order to set the div's position
I tried to use Hibernate Envers to log the entity histroy. but failed. My
I tried to use dat.GUI in the following three.js example . I just did
I tried to use an image file in my HTML template. But when I
I tried to use object expression to extend the IDelegateEvent, but in fsi there
If I have the following data: test1.test2 AND test1.test2 What regex can I use
I have the following patterns: private static Regex rgxDefinitionDoMatch = new Regex(@d:(?<value>(?:(?!c:|d:|p:).)+), RegexOptions.Compiled); private

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.