regex - Perl Modifiers /^ AND $ -
somebody please explain me in layman terms use of modifiers /^ , $ in below statement;
elsif ($keyword =~ /^verse$/gi)
i information ^ matches beginning of line , $ matches end of line, supposed mean? explain me if
condition considered above statement.
these characters "zero-width assertions". don't stand group of characters, positions in string.
^
means expect pattern @ beginning of line or record.$
means expect pattern @ end of line or record
in standard matching mode (without trailing switch /m
), perl considers first record in string total searchable space. /m
switch, perl considers records in string, each record delimited current value of $/
(also $rs
use
english
qw($rs);
).
so if you're searching through couple of records , know pattern occurs @ beginning or end, can use characters specify that. (absolute start of string \a
, absolute end \z
place before record separator ends entire string or \z
place after every single character in string. perl best practices prefers uniform use of \z
.)
to clarify, standard record line of input, delimited systems' line separator.
to answer specific question: condition true if first record in string in $keyword
matches 'verse'
. strings aren't expected contain that, might use
if ($keyword eq 'verse' ) { ... }
Comments
Post a Comment