Recently I downloaded a source (LevBot) and then I see this line:
} elsif($text =~ /^slaps $levbot_nick/i) {
- But what
/^and/ido? - Why to use they?
I think this is regular expression, I'm right?
Recently I downloaded a source (LevBot) and then I see this line:
} elsif($text =~ /^slaps $levbot_nick/i) {
/^ and /i do?I think this is regular expression, I'm right?
Yes. See the perlre documentation. Briefly, /^ matches the start of a line, and /i means it's case-insensitive.
Thats a regular expression
/^slaps $levbot_nick/i
/^ means starts with (actually ^ alone)
/i means ignore case (i alone after / /)
first and last / slashes are boundary of regex
/ Delimiter denoting start of regex (The char / is not part of the regex)^ Matches the start of a line / Delimiter for the end of the regex (not part of the regex)i Flag to make the regex case insensitiveOther flags possible are:
g Global s Dot matches new line charactersx Extended - ignores whitespaces in the pattern and allows commentsm Multiline mode.Yes, this is a regular expression.
/ on either side mark the pattern's beginning and end.^ at the start of the patten means "only match this at the beginning of the string, and nowhere else."i after the end of the pattern is a modifier, it means "be case-insensitive when matching this", since the default is case-sensitive./^ matches the beginning of a line.
/i means case insensitive search.
This syntax in Perl was inspired by awk's /xxx/ Pattern matching feature.