Thread pos($string) zwischen //g Regexes in Schleife? (9 answers)
Opened by GoodFella at 2007-03-27 18:55

GoodFella
 2007-03-28 15:36
#75450 #75450
User since
2007-01-09
192 Artikel
BenutzerIn
[default_avatar]
[quote=Taulmarill,28.03.2007, 10:31]was hältst du davon:
Code: (dl )
1
2
3
4
5
my $str = 'bla_blub_bla';
$str =~ /([^_]+)_/s;
print '1. Mal: Position='.$+[0].", Gefunden: $1\n";
$str =~ /([^_]+)_/s;
print '2. Mal: Position='.$+[0].", Gefunden: $1\n";


perlvar[/quote]
cool... dachte, ich hätte mal gelesen, dass speichern in $1, $2, ... nur in Verbindung mit dem g-Modifier funktioniert...
Schön, dass es anders ist :D
Danke.

Achja, der betroffene Part von perlvar sagt:
Quote
$LAST_PAREN_MATCH
$+ The text matched by the last bracket of the last successful
search pattern. This is useful if you don't know which one of a
set of alternative patterns matched. For example:

/Version: (.*)|Revision: (.*)/ && ($rev = $+);

(Mnemonic: be positive and forward looking.) This variable is
read-only and dynamically scoped to the current BLOCK.
}

Dass die Position bei Listenkontext in $+[0] steht, davon finde ich aber nichts.. In $+[1] befindet sich nach meinen Tests ($+[0] - 1) .. keine Ahnung welchen Zweck das hat.. oder hab ich was überlesen? :)

View full thread pos($string) zwischen //g Regexes in Schleife?