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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:36:09+00:00 2026-06-13T17:36:09+00:00

I need to know if there is a regular expression for testing for the

  • 0

I need to know if there is a regular expression for testing for the presence of numbers in strings that:

  • Matches Lorem 20 Ipsum
  • Matches Lorem 2,5 Ipsum
  • Matches Lorem 20.5 Ipsum
  • Does not match Lorem 2% Ipsum
  • Does not match Lorem 20.5% Ipsum
  • Does not match Lorem 20,5% Ipsum
  • Does not match Lorem 2 percent Ipsum
  • Does not match Lorem 20.5 percent Ipsum
  • Does not match Lorem 20,5 percent Ipsum
  • Matches Lorem 20 Ipsum 2% dolor
  • Matches Lorem 2,5 Ipsum 20.5% dolor
  • Matches Lorem 20.5 Ipsum 20,5% dolor

That is, a regular expression that can tell me if in a string there is one or many numbers, but not as percentage value.

I’ve tried something as /[0-9\.,]+[^%]/, but this not seems to work, I think because digits then not a percentage sign match also the 20 in the string 20%. Additionally, I don’t know how to tell not the entire percent string in addition to the % char.

  • 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-13T17:36:11+00:00Added an answer on June 13, 2026 at 5:36 pm

    This will do what you need:

    \b                     -- word boundary
    \d+                    -- one or more digits
    (?:\.\d+)?             -- optionally followed by a period and one or more digits
    \b                     -- word boundary
    \s+                    -- one or more spaces
    (?!%|percent)          -- NOT followed by a % or the word 'percent'
    

    –EDIT–

    The meat here is the use of a “negative lookahead” on the final line that causes the match to fail if any of a percent-sign or the literal “percent” occurs after a number and one or more spaces. Other uses of negative lookahead in JavaScript RegExps can be found at Negative lookahead Regular Expression

    –2ND EDIT–
    Congrats to Enrico for solving the most general case but while his solution below is correct, it contains several extraneous operators. Here is the most succinct solution.

    (                         -- start capture
      \d+                     -- one or more digits
      (?:[\.,]\d+)?           -- optional period or comma followed by one or more digits
      \b                      -- word boundary
      (?!                     -- start negative lookahead
        (?:[\.,]\d+)          -- must not be followed by period or comma plus digits
      |                       --    or
        (?:                   -- start option group
          \s?%                -- optional space plus percent sign
        |                     --   or
          \spercent           -- required space and literal 'percent'
        )                     -- end option group
      )                       -- end negative lookahead
    )                         -- end capture group
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a regular expression that will allow only a to z and 0
I need a regular expression that will match any string containing at most 2
I need a regular expression find and replace that I'm a little stuck on.
How can I convert a string to a regular expression that matches itself in
I'm trying to figure out a regular expression in JS that matches between two
I am trying to apply negation on regular expression in .Net. It does not
I need to know if there's any way (or another distinct approach) to an
I need to know if there's a way in PHP to echo a string
I need to know if there is a way to create a custom shortcut
I know there has to be a way: I need help getting any hot

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.