RegEx: Using backreference in match

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
Thorsten Walenzyk [ Di, 26 Oktober 2004 17:44 ] [ ID #449039 ]

Re: RegEx: Using backreference in match

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
someone [ Mi, 27 Oktober 2004 00:37 ] [ ID #450083 ]
Perl » alt.perl » RegEx: Using backreference in match

Vorheriges Thema: decompile a perl2exe
Nächstes Thema: Win32::Ole and Call by reference