Regular Expressions
Regular expressions are a big part of the Perl language. They are essential to know and use when processing texts. And that's what Perl is good for.
In short, regular expressions are special patterns when applied to strings either match them or not, capture various substrings, modify the initial substring by substituting parts of it and so on.
The most common usage for regular expression is to find out if a particular string can be found in another string.
my $string = 'Hello, world!';
if ($string =~ m/Hello/) {
say 'We found Hello!';
}
So here are two new things: =~ and m// (m is for match). There is also an opposite !~ which is evaluated to True when the regular expression is not matched.
my $string = 'Hello, world!';
if ($string !~ m/Bye/) {
say 'No Bye was found';
}
Regular expressions can be really sophisticated. For example we want to check if a string has a or o characters:
my $string = 'Hello';
if ($string =~ m/a|o/) {
say 'a or o was found';
}
Metacharacters
Some characters in regular expression (as | in previous example) are special. They
