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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:46:01+00:00 2026-06-11T01:46:01+00:00

I have my Regular Expression /'(.*)(?:(?:’\s*,\s*)|(?:’\)))/ and my test code (‘He said, You’re cool.’

  • 0

I have my Regular Expression /'(.*)(?:(?:'\s*,\s*)|(?:'\)))/
and my test code ('He said, "You're cool."' , 'Rawr')
(My test code simulates parameters being passed into a function.)

I will explain my Regular Expression as I understand it and hopefully a few of you can shed some light on my problem.

1)/' means at the beginning of the matched string, there needs to be '

2)(.*) means capture any character except \n 0 or more times

3)(?:(?:4)|(?:5)) means don’t capture but try to do step 4 and if it doesn’t work try step 5

4)(?:'\s*,\s*) means don’t capture but there needs to be a ' with 0 or more whitespace characters followed by a , with 0 or more whitespace characters

5)(?:'\)) means don’t capture but there needs to be ')

So it seems that it should return this (and this is what I want):
'+He said, "You're cool."+' ,
But it returns:
'+He said, "You're cool."' , 'Rawr+')

If I change my test code to ('He said, "You're cool."' , 'Rawr' (no end parenthesis) it returns what I want, but as soon as I add that last parenthesis, then it seems that my OR operator does whatever it wants to. I want it to test first if there is a comma, and break there if there is one, and if there is not one check for a parenthesis.

I’ve tried switching the spots of step 4 and step 5, but still the OR operator seems to always default to the (?:'\)) side.
How can I match the shortest amount possible?

  • 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-11T01:46:02+00:00Added an answer on June 11, 2026 at 1:46 am

    I don’t think your problem is the OR operator, but the greediness of the .*. It will match your full string, and then back-track until the following expressions match. The first match in this backtracking process will be 'He said, "You're cool."' , 'Rawr+'). Try .*? instead!

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

Sidebar

Related Questions

Anybody have a regular expression to replace the following code: <a href=originalLink>hi</a> with: <a
I have this regular expression to test (\&TRUNC)[\(]{1,}(.+)[\)]{1,} And I have this tester ((((&TRUNC((1800,000
I have this regular expression for URL ^(((https?|ftp|file|)://)|(www))[-A-Za-z0-9+&@#/%?=~_|!:,.;]*[-A-Za-z0-9+&@#/%=~_|]$ Almost all my test scenarios works
I have a regular expression (REGEX 1) plus some Perl code that picks out
Regular Expression problem I have Regular Expression code handling graphic files. $view[content] = preg_replace(/(\<img
I have a regular expression to find :ABC:`hello` pattern. This is the code. format
I have a regular expression to validate the dates and it works fine, this
I have a regular expression which allows the value range '1111' - '999999', excluding
I have a regular expression which uses GroupCollection s in it's capture to capture
I have a regular expression to validate a input value. At this point 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.