www.delorie.com/gnu/docs/regex/regex_42.html   search  
 
Buy the book!


Regex

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

6. What Gets Matched?

Regex usually matches strings according to the "leftmost longest" rule; that is, it chooses the longest of the leftmost matches. This does not mean that for a regular expression containing subexpressions that it simply chooses the longest match for each subexpression, left to right; the overall match must also be the longest possible one.

For example, `(ac*)(c*d[ac]*)\1' matches `acdacaaa', not `acdac', as it would if it were to choose the longest match for the first subexpression.


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003