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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:12:59+00:00 2026-06-01T13:12:59+00:00

I would like to match positive and negative numbers (no decimal or thousand separators)

  • 0

I would like to match positive and negative numbers (no decimal or thousand separators) inside a string using .NET, but I want to match whole words only.
So if a string looks like

redeem: -1234
paid: 234432

then I’d like to match -1234 and 234432

But if text is

LS022-1234-5678
FA123245

then I want no match returned. I tried

\b\-?\d+\b

but it will only match 1234 in the first scenario, not returning the “-” sign.

Any help is appreciated. Thank you.

  • 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-01T13:13:01+00:00Added an answer on June 1, 2026 at 1:13 pm

    Well, I’m sure this is far from perfect, but it works for your examples:

    (?<=\W)-?(?<!\w-)\d+
    

    If you want to allow underscores just before the number, then I’d use this modification:

    (?i)(?<=[^a-z0-9])-?(?<![a-z0-9]-)\d+
    

    Let me know of any issues and I’ll try and help. If you’d like me to explain either of them, let me know that too.

    EDIT

    To only match if there is a space or tab just before the number / negative sign (as noted in the comment below), this could be used:

    (?<=[ \t])-?\d+
    

    Note that it will match e.g. on the first number series of a telephone number, time or date value, and will not match if the number is at the beginning of the line (after a newline) – make sure this is what you intend 😀

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

Sidebar

Related Questions

i would like to match a part of the string using lookarounds, but only
I would like to match the numbers inside an HTML tag such as: Sometext<sometag><htmltag>123123</htmltag></sometag>
I would like to regex match a sequence of bytes when the string '02
I would like to be able to match a string literal with the option
I would like to match this 'wildcard %' in MySQL. I tried using escape
Iceland :Country\nEurope::Continent\nReykjavik:City with the above string, i would like to match words that appear
I have a string: $string = Created on: 06-Sep-08; I would like to match
I have a Java pattern I would like to match. I want to take
I would like a JavaScript regular expression that will match time using the 24
So far so good, but I would like to match Health and Beauty instead

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.