![]() |
![]() |
10 Einträge, 1 Seite |
QuoteC:\Dokumente und Einstellungen\Administrator>perldoc -f pos
pos SCALAR
pos Returns the offset of where the last "m//g" search left off for
the variable in question ($_ is used when the variable is not
specified). Note that 0 is a valid match offset. "undef"
indicates that the search position is reset (usually due to
match failure, but can also be because no match has yet been
performed on the scalar). "pos" directly accesses the location
used by the regexp engine to store the offset, so assigning to
"pos" will change that offset, and so will also influence the
"\G" zero-width assertion in regular expressions. Because a
failed "m//gc" match doesn't reset the offset, the return from
"pos" won't change either in this case. See perlre and perlop.
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/perl use strict; use warnings; my $str = 'bla_blub_bla'; $str =~ /([^_]+)_/sg; print '1. Mal: Position='.pos($str).", Gefunden: $1\n"; $str =~ /([^_]+)_/sg; print '2. Mal: Position='.pos($str).", Gefunden: $1\n";
Quote1. Mal: Position=4, Gefunden: bla
2. Mal: Position=9, Gefunden: blub
pos($str) = 0;
$str .= '';
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";
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";
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.
}
Quote@LAST_MATCH_END
@+
This array holds the offsets of the ends of the last successful submatches in the currently active dynamic scope. $+[0] is the offset into the string of the end of the entire match. This is the same value as what the pos function returns when called on the variable that was matched against. The nth element of this array holds the offset of the nth submatch, so $+[1] is the offset past where $1 ends, $+[2] the offset past where $2 ends, and so on. You can use $#+ to determine how many subgroups were in the last successful match. See the examples given for the @- variable.
1
2
3
4
5
6
7
8
#!/usr/bin/perl
use strict;
use warnings 'all';
my $str = 'bla_blub_bla';
print( $str =~ /([^_]+)_/g , "\n");
print( $str =~ /([^_]+)_/g , "\n");
![]() |
![]() |
10 Einträge, 1 Seite |