Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks
I'm trying to find the position of the match BEGINNING found with the following Regex, but I have really no idea how. The problem is that I'm searching in a span, so I really do not know how to come to the beginning position (I normally find it counting the length (characters) of the matching variables and "moving back" of that value starting from the pos($text) value).
my $text=<<EOF I'm trying to find the position of the match BEGINNING found with the +following Regex, but I have really no idea how. The problem is that I +'m searching in a span, so I really do not know how to come to the be +ginning position (I normally find it counting the length (characters) + of the matching variables and "moving back" of that value starting f +rom the pos($text) value). EOF my $UserInputPart1 = "to"; my $UserInputPart1 = "the"; while (($text=~ /$UserInputPart1\W+(?:\w+\W+){0,5}?$UserInputPart2/gi) + || ($text=~ /$UserInputPart2\W+(?:\w+\W+){0,5}?$UserInputPart1/gi)){ my $position = pos($text); print $position . "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find initial position of match iin regexp with variable span
by AppleFritter (Vicar) on Oct 14, 2015 at 09:36 UTC | |
by Anonymous Monk on Oct 14, 2015 at 09:44 UTC |