 |
|
 |
| |
Developer on focus
Anton Zamov is a dipl. engineer with more than 6 years of active professional
experience and many awards ...
read more>>
|
|
 |
 |
 |
|
 |
|
 |
| |
|
Information for some special symbols in Perl regular expressions.
|
=~
This operator appears between the string var you are comparing, and the regular expression you're looking for (note that in selection or substitution a regular expression operates on the string var rather than comparing). Here's a simple example:
$string =~ m/Bill Clinton/; #return true if var $string contains the name of the president
$string =~ tr/Bill Clinton/Al Gore/; #replace the president with the vice president
!~
Just like =~, except negated. With matching, returns true if it DOESN'T match. I can't imagine what it would do in translates, etc.
/
This is the usual delimiter for the text part of a regular expression. If the sought-after text contains slashes, it's sometimes easier to use pipe symbols (|) for delimiters, but this is rare. Here are simple examples:
$string =~ m/Bill Clinton/; #return true if var $string contains the name of the president
$string =~ tr/Bill Clinton/Al Gore/; #replace the president with the vice president
m
The match operator. Coming before the opening delimiter, this is the "match" operator. It means read the string expression on the left of the =~, and see if any part of it matches the expression within the delimiters following the m. Note that if the delimiters are slashes (which is the normal state of affairs), the m is optional and often not included. Whether it's there or not, it's still a match operation. Here are some examples:
$string =~ m/Bill Clinton/; #return true if var $string contains the name of the president
$string =~ /Bill Clinton/; #same result as previous statement
^
This is the "beginning of line" symbol. When used immediately after the starting delimiter, it signifies "at the beginning of the line". For instance:
$string =~ m/^Bill Clinton/; #true only when "Bill Clinton" is the first text in the string
$
This is the "end of line" symbol. When used immediately before the ending delimiter, it signifies "at the end of the line". For instance:
$string =~ m/Bill Clinton$/; #true only when "Bill Clinton" is the last text in the string
i
This is the "case insensitivity" operator when used immediately after the closing delimiter. For instance:
$string =~ m/Bill Clinton/i; #true when $string contains "Bill Clinton" or BilL ClInToN"
|
About the author of this programming example or tutorial:
Anton Zamov is a software engineer with more than6 years
of active experience in web and software development and design.
Anton Zamov has extensive experience and broad knowledgebase
in C# and JAVA programming and has created a lot of
running e-commerce systems, portals and content management
systems using PHP and other web development technologies.
For more information about Anton Zamov, you may visit the personal web site of
Anton Zamov.
|
|
|
 |
 |
 |
|
|