[#3006] mismatched quotation — "stevan apter" <apter@...>

ruby documentation uses a punctuation convention i've never seen

13 messages 2000/05/27

[ruby-talk:02903] Re: Does anyone have any good examples

From: ts <decoux@...>
Date: 2000-05-19 06:05:15 UTC
List: ruby-talk #2903
>>>>> "D" == Dave Thomas <Dave@thomases.com> writes:

D> I'm looking for some good examples of the (?>...) construct. Anything
D> good out there?

 The best is perhaps to look at the documentation of perl.

 (?> ... ) is generally used in 2 situations : 

  * to avoid what is called "eternal" matches. This mean that you find it
 in complex regexp (for example when you don't want to have backtracing).

 If one day you'll try to write a "buggy" html parser you'll perhaps
 finished with something like this (this is only a small part of the 
 regexp :-)) 

  (?=[a-zA-Z/])(?>[^"'>]+(?:"[^"]*"|'[^']*')?)+)>

 * another case, given in the doc of perl, is when ()* don't give the
   expected result. If you want to match non-whitespace characters
   following a `#' (with possible space after it) it's best to use

  /(?>#[ \t]*)(.+)/

 because with the regexp /#[ \t]*(.+)/ and the line "#    ", the regexp
 will match ` ' for $1


Guy Decoux

In This Thread

Prev Next