-1

Consider (\w[0-9]).*\1 RegEx, it matches to d1akdhfafd1, R2ddsfasfasfdsfdR2, etc. .

Is is possible to write a RegEx that that match to following too: D1dfsadfadsfE3, z6adfdasfdfr2, e3654654e0 ,....?

\w[0-9] is just an example, please consider general form (::A_Complex_Pattern::).*\1

Handsome Nerd
  • 17,114
  • 22
  • 95
  • 173
  • 1
    You *might* mean recursion. http://php.net/regexp.reference.recursive - apart from that provide a PHP example with a subject string, your pattern, the actual outcome and the outcome you're looking for. It's not that clear what you ask about - a code example makes this always immediately clear. – hakre Nov 10 '12 at 18:05

1 Answers1

0

PHP's regex engine (PCRE) supports recursion. A few others do, but you generally shouldn't count on it. However, if the engine does, then you can insert patterns used elsewhere like this:

(\w\d).*(?1)

Where the numbering as the same as that for backreferences. (?R) would insert the whole pattern.

Martin Ender
  • 43,427
  • 11
  • 90
  • 130
  • 1
    @Reza I was in fact wrong. I updated the answer with a solution to your problem. – Martin Ender Nov 10 '12 at 18:18
  • Beside PCRE and related languages is there any other language that support recursion too? Is there any way to emulate this for use in JS? – Handsome Nerd Nov 11 '12 at 11:17
  • @Reza according to wikipedia [only Boost does](http://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines#Language_features) – Martin Ender Nov 11 '12 at 11:23