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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:48:07+00:00 2026-06-11T06:48:07+00:00

I know this stuff has been talked about a lot, but I’m having a

  • 0

I know this stuff has been talked about a lot, but I’m having a problem trying to match the following…

Example input: “test test 310-315”

I need a regex expression that recognizes a number followed by a dash, and returns 310. How do I include the dash in the regex expression though. So the final match result would be: “310”.

Thanks a lot – kcross

EDIT: Also, how would I do the same thing but with the dash preceding, but also take into account that the number following the dash could be a negative number… didnt think of this one when I wrote the question immediately. for example: “test test 310–315” returns -315 and “test 310-315” returns 315.

  • 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-11T06:48:09+00:00Added an answer on June 11, 2026 at 6:48 am
    Regex regex = new Regex(@"\d+(?=\-)");
    

    \d+ – Looks for one or more digits

    (?=\-) – Makes sure it is followed by a dash

    The @ just eliminates the need to escape the backslashes to keep the compiler happy.

    Also, you may want this instead:

    \d+(?=\-\d+)
    

    This will check for a one or more numbers, followed by a dash, followed by one or more numbers, but only match the first set.


    In response to your comment, here’s a regex that will check for a number following a -, while accounting for potential negative (-) numbers:

    Regex regex = new Regex(@"(?<=\-)\-?\d+");
    

    (?<=\-) – Negative lookbehind which will check and make sure there is a preceding -

    \-? – Checks for either zero or one dashes

    \d+ – One or more digits

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

Sidebar

Related Questions

I know this has been asked before and Ive tried lots of stuff but
Know this might be rather basic, but I been trying to figure out how
I know the tagging stuff has been mentioned many times, but I can't seem
I know this sort of question has been asked before , but I still
Ok guys I know this question has been asked before but I am very
So, I know this has been done to death but all the answers I've
I know this question has been asked many times before but I tried out
I know that this subject has been seen many times here, but I didn't
I know this question has been asked several times, but I would like to
I know this kind of question has been asked before, but the general solution

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.