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 useenglishqw($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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -