For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > October 2004 > RegEx: Using backreference in match









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author RegEx: Using backreference in match
Thorsten Walenzyk

2004-10-26, 3:56 pm

Hi all,

I have a question regarding Regular Expression and backreference.

Is it possible to use backreferences within the same reg ex?
e.g.
m/SomeText([0-9]+).*?SomeOtherText($1)/gs

$1 should be the number of the match behind "SomeText"

BR Thorsten


John W. Krahn

2004-10-26, 8:55 pm

Thorsten Walenzyk wrote:
>
> I have a question regarding Regular Expression and backreference.
>
> Is it possible to use backreferences within the same reg ex?
> e.g.
> m/SomeText([0-9]+).*?SomeOtherText($1)/gs
>
> $1 should be the number of the match behind "SomeText"


Yes it is possible, like this:

/SomeText(\d+).*?SomeOtherText\1/gs


John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com