2

Recently, somewhere on the web*, I found a reference for regular expressions which described a "third way" of greediness, different both from greedy (.*) and lazy (.*?) matching.

I've now tried searching SO, Googling, and even searching my browser history, but to no avail.

Can anyone make a good guess at what it was I saw?


Clarification: it referred to what was for me a new construct (something like .*+), and I believe it even had a name for it (something like, but probably not, "passively greedy").


* I appreciate that "somewhere on the web" is about as helpful as "in the Library of Babel" or "in the Mandelbrot set", but please try to help

AndersTornkvist
  • 2,610
  • 20
  • 38
Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62
  • Well, well, six years later somebody finally downvoted this question. Would you care to share with us what your criticism is? That way we can learn, and improve. Alternatively, if you were just having a bad day, you can always vote it back up again when life gets better. – Brent.Longborough Jan 27 '15 at 17:18
  • The dv is probably because your question is vague and has no context. This page is provably low-value to researchers because it has been on SO for over a decade and has very few upvotes -- anywhere on the page. – mickmackusa Jul 05 '21 at 09:22

6 Answers6

5

I think you are referring to "posessive" matching. Java describes it on this page: http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html

Possessive quantifiers, which greedily match as much as they can and do not back off, even when doing so would allow the overall match to succeed.

The syntax is the same as what you described (.*+) .

Community
  • 1
  • 1
Adam Crume
  • 15,614
  • 8
  • 46
  • 50
4

This maybe? http://www.regular-expressions.info/repeat.html

An Alternative to Laziness

In this case, there is a better option than making the plus lazy. We can use a greedy plus and a negated character class: <[^>]+>.

mletterle
  • 3,968
  • 1
  • 24
  • 24
2

There are various different regex packages. PCRE (Perl-compatible regular expressions) are used (more or less) in Perl, Java, PHP and probably other languages. The PCRE man page might be regarded as the definitive reference. It describes possessive quantifiers (e.g. *+ and ++), which are a shorthand for atomic groups.

Bennett McElwee
  • 24,740
  • 6
  • 54
  • 63
1

Well, not exactly a reference, but good still. Mastering Regular Expressions

There is also a "reference" book from O'Reilly, but I can't testify on it. Just saw it for the first time.

Rook
  • 60,248
  • 49
  • 165
  • 242
0

I always keep a copy of this regular expressions cheat sheet handy in my cube.

Barry
  • 492
  • 1
  • 4
  • 12
0

Thank you all. The key to getting my memory back was "possessive", not "passive".

Here are a couple of useful references:

Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62