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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:56:58+00:00 2026-05-30T08:56:58+00:00

The matches can be overlapped. But if multiple matches are found starting from a

  • 0

The matches can be overlapped.

But if multiple matches are found starting from a same position, pick the short one.

For example, to find regexp parttern “a.*d” in a string “abcabdcd”, the answer should be {“abcabd”, “abd”}. And “abcabdcd” and “abdcd” should not be included.

  • 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-30T08:57:00+00:00Added an answer on May 30, 2026 at 8:57 am

    Most RE engines only match an RE once and greedily by default, and standard iteration strategies built around them tend to restart the search after the end of the previous match. To do other than that requires some extra trickery. (This code is Tcl, but you should be able to replicate it in many other languages.)

    proc matchAllOverlapping {RE string} {
        set matches {}
        set nonGreedyRE "(?:${RE}){1,1}?"
        set idx 0
        while {[regexp -indices -start $idx $nonGreedyRE $string matchRange]} {
            lappend matches [string range $string {*}$matchRange]
            set idx [expr { [lindex $matchRange 0] + 1 }]
        }
        return $matches
    }
    puts [matchAllOverlapping a.*d abcabdcd]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version: How can I get a regex that matches a@a.aaaa but not a@a.aaaaa
I have searched but I can't find anything that matches my query. I have
How can I find the route that matches a string url in ASP.NET MVC?
How can I find the index in a string that matches a boost regex?
Is there a way that I can find out how many matches of a
As I just learned from this question , .NET regexes can access individual matches
preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can
I can't seem to figure out how to find substring matches with SOLR, I've
We can use closest(selector) to find the first ancestor element that matches the selector.
I have a string which can contain multiple matches (any word surrounded by percentage

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.