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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:04:45+00:00 2026-05-27T16:04:45+00:00

I am new to regular expression and this may be a very easy question

  • 0

I am new to regular expression and this may be a very easy question (hopefully).

I am trying to use one solution for 3 kinds of string

  • "45%", expected result: "45"
  • "45", expected result: "45"
  • "", expected result: ""

What I am trying (let the string be str):

str.match(/(.*)(?!%*)/i)[1]

This is in my head would sound like "match any instance of anything up until ‘%’ if it is found, or else just match anything"

In firebug’s head, it seems to sound more like "just match anything and completely disregard the negative lookahead". Also to make it lazy – (.*)? – doesn’t seem to help.

Let’s forget for a second that in this specific situation I am only matching numbers, so a /\d*/ would do. I am trying to understand a general rule so that I can apply it whenever.

Anybody would be so kind to help me out?

  • 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-27T16:04:46+00:00Added an answer on May 27, 2026 at 4:04 pm

    How about the simpler

    str.match(/[^%]*/i)[0]
    

    Which means, match zero-or-more character, which is not a %.


    Edit: If need to parse until </a>, then you could parse a sequence pf characters, followed by </a>, then then discard the </a>, which means you should use positive look-ahead instead of negative.

    str.match(/.*?(?=<\/a>|$)/i)[0]
    

    This means: match zero-or-more character lazily, until reaching a </a> or end of string.

    Note that *? is a single operator, (.*)? is not the same as .*?.

    (And don’t parse HTML with a single regex, as usual.)

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

Sidebar

Related Questions

I am trying to use a regular expression like this: string Size= 10.5M; Match
I'm new to regular expression and just can't seem to figure this out: '/^[A-Za-z0-9](?:.[A-Za-z0-9]+)$/'
I'm stil pretty new to regular expression and just started learning to use awk.
How can I put in this regular expression Regex PhRegEx = new Regex(@^[a-zA-Z0-9-+_,(): ]*$,
I'm trying to run this regular expression [\s]+(<)|(>)[\s]+ dim myRegExp as object Set myRegExp
I'm new to regular expressions so this isn't strictly a Notepad++ question. Here's the
I'm new to regular expressions and would appreciate your help. I'm trying to put
I am completely new to regular expressions ,and I am trying to create a
I am fairly new to regular expressions and the more and more I use
I am very very new to Python and I could use your help. I

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.