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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:20:20+00:00 2026-06-12T09:20:20+00:00

The string I am using as my subject is: ‘Save 68% on a 4

  • 0

The string I am using as my subject is:

‘Save 68% on a 4 Day/3 Night vacation at. Only $249!’

I’m using '.\*(\b((enjoy|save)( up to| an extra)?|starting at|as low as|just|only)\b ([0-9]{1,3} ?\%|\$[0-9]+(\.[0-9]{2})?)).\*/i' to try to match a part of the above string a extract it.

I’m using '$1' as the replacement, so my full preg_match looks like

preg_match('.*(\b((enjoy|save)( up to| an extra)?|starting at|as low as|just|only)\b ([0-9]{1,3} ?\%|\$[0-9]+(\.[0-9]{2})?)).*/i', '$1', 'Save 68% on a 4 Day/3 Night vacation at. Only $249!')

It should match 'Save 68%' first but it keeps returning 'Only $249'.

I’ve found that if I add a question mark after the first wildcard '.\*?(\b((enjoy|save)( up to| an extra)?|starting at|as low as|just|only)\b ([0-9]{1,3} ?\%|\$[0-9]+(\.[0-9]{2})?)).\*/i' it does return 'save 68%'. Is there another way around this. It seems to have to do with my grouping. As I’ve found that

preg_match('/.*\b(enjoy|save)( up to| an extra)?|starting at|as low as|just|only\b.*/i', '$1', 'Save 68% on a 4 Day/3 Night vacation at. Only $249!')

returns 'save' like it should, but I can’t get the same thing to work on the full statement.

  • 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-12T09:20:21+00:00Added an answer on June 12, 2026 at 9:20 am

    The reason why adding a question mark after the first wildcard works, is that .* is greedy, and the question mark (.*?) makes it lazy. A greedy operator will match as much as possible, which in your case is the whole line (.* says “match anything as many times as possible”). Making it lazy will cause it to match as little as possible. Read more about this in the repetition section of the PCRE manual pages.

    For your particular problem, what’s wrong with using the lazy operator? If it results in what you want, I say go with it.

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

Sidebar

Related Questions

How can I validate a string using Regular Expressions to only allow alphanumeric characters
It seems that when using a primitive type (string, number) as the this subject
Possible Duplicate: Find text string using jQuery? How do you find a text string
I have a string using the pipe symbol | as the delimiter. However, the
Consider: Dim line As String Using readFile As New StreamReader(SalesUpdateFile) While (line = readFile.ReadLine)
I want to draw string using Graphics with Rectangle border outside the string. This
I am creating an XML string using JQuery. I would like to open a
I would like to compare 4 character string using wildcards. For example: std::string wildcards[]=
I need to extract parts of a string using regex in Python. I'm good
When decoding/encoding a utf8 string using json_encode/json_decode I do not get back the string

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.