[dokuwiki] Re: back references in syntax plugin regex?

  • From: Christopher Smith <chris@xxxxxxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Sun, 2 May 2010 21:35:47 +0100

On 2 May 2010, at 18:34, Simon Elliot wrote:

> Just a simple question for the experts out there:  is it possible to use back 
> references in a syntax plugin regex pattern?  I'm trying to look for words 
> with tripled letters at the beginning, i.e. the first 3 characters are the 
> same, e.g. aaa bbb ccc, etc... I'm using the following regex, but it is not 
> being recognised by the lexer:
> 
> "\w\1\1\w+"
> 
> Am I doing something wrong or is it just not possible?
> 

Both.  I think the pattern you're looking for requires the first letter in 
parenthesis, so (\w)\1\1\w+. My recollection is the lexer only allows groups if 
they are non-captured groups.  This is because the lexer itself is a very large 
compound regex and it uses the matching subgroup to determine which syntax is 
being matched.  FYI, you can use lookahead and lookbehind.

- Chris

Other related posts: