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

  • Home
  • SEARCH
  • 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 7615295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:36:39+00:00 2026-05-31T02:36:39+00:00

To match a string with pattern like: -TEXT-someMore-String To get -TEXT- , I came

  • 0

To match a string with pattern like:

-TEXT-someMore-String

To get -TEXT-, I came to know that this works:

/-(.+?)-/ // -TEXT-

As of what I know, ? makes preceding token as optional as in:

colou?r matches both colour and color

I initially put in regex to get -TEXT- part like this:

/-(.+)-/

But it gave -TEXT-someMore-.

How does adding ? stops regex to get the -TEXT- part correctly? Since it used to make preceding token optional not stopping at certain point like in above example ?

  • 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-31T02:36:40+00:00Added an answer on May 31, 2026 at 2:36 am

    As you say, ? sometimes means “zero or one”, but in your regex +? is a single unit meaning “one or more — and preferably as few as possible”. (This is in contrast to bare +, which means “one or more — and preferably as many as possible”.)

    As the documentation puts it:

    However, if a quantifier is followed by a question mark,
    then it becomes lazy, and instead matches the minimum
    number of times possible, so the pattern /\*.*?\*/
    does the right thing with the C comments. The meaning of the
    various quantifiers is not otherwise changed, just the preferred
    number of matches. Do not confuse this use of
    question mark with its use as a quantifier in its own right.
    Because it has two uses, it can sometimes appear doubled, as
    in \d??\d which matches one digit by preference, but can match two if
    that is the only way the rest of the pattern matches.

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

Sidebar

Related Questions

I want to match any string that has a recurring cycle. Like in this
How do I match this pattern multiple times in a string for all of
From a string, I need to pull out groups that match a given pattern.
I have a string such as: #sometag-{serialized-data-here} And I want to match this pattern
Let's say I'm matching with a pattern that has subexpressions like this: Regex myRegex
I have a string of text like this: This is a[WAIT] test. What I
I would like to get all digits of a string like this : 0
I have a pattern to match with the string: string pattern = @asc I
I'm working on a string pattern match algorithm. I use NSRegularExpression for finding the
If I want to match() a string with the following pattern: 12345678_12345678 What would

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.