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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:46:47+00:00 2026-06-06T08:46:47+00:00

Possible Duplicate: Regex question mark I am trying to figure out how to parse

  • 0

Possible Duplicate:
Regex question mark

I am trying to figure out how to parse out the text inside the parenthesis but between the single quotes in a statement. For example, if I have the following statement:

(I have a 'cat', 'hat');

I want the result to be

cat
hat

I managed to figure it out by experimenting with the different metacharacters defined in wikipedia (http://en.wikipedia.org/wiki/Regular_expression) however I still have trouble understanding why it works.

I’ve tried this : \'(.*)\'

My understanding of this regex: I want to get the characters in between the single quotes ' and these characters matches any single character . zero or more times *.

This resulted in:

cat', 'hat

After playing around with a bunch of regex I finally ended up with this by accident: \'(.*?)\'

This resulted in:

cat
hat

Why does this work? (In particular I don’t understand how the ‘?’ works.)

  • 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-06T08:46:49+00:00Added an answer on June 6, 2026 at 8:46 am

    The default behavior of the regular expression to make the longest possible match in the string. This is referred to as being “greedy.”

    You are correct that ? normally just means to match the preceding item (e.g., character) one or more times, but *? is a special case called “lazy star” that switches the regular expression evaluator into a “lazy” mode. In this mode, the evaluator first tries to skip the preceding item (and complete a match without it), before then “going back” for it.

    The net result is just what you’ve observed: it will match shorter strings that satisfy the search criteria instead of (the default) whereby it would just find the longest possible match.

    A handy resource for testing out regular expressions is here, and a nice description of the various options, including lazy star, is here.

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

Sidebar

Related Questions

Possible Duplicate: Regex to parse youtube yid your probably thinking not another one, but
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: RegEx match open tags except XHTML self-contained tags How to remove single
Possible Duplicate: Regex - nested patterns - within outer pattern but exclude inner pattern
Possible Duplicate: My regex is not working properly Suppose I have long text. From
Possible Duplicate: Regex for checking if a string has mismatched parentheses? I'm trying to
Possible Duplicate: php regex <b> to <b> Inside my admin panel I have a
Possible Duplicate: replace all “foo” between () Hello, I tried to use regex to
Possible Duplicate: Regular Expression to escape double quotes inside single quotes I need a
Possible Duplicate: notepad++ Inverse Regex replace (all but string) Let's say I have the

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.