
The “/g” modifier can be used to process all regex matches in a string. Thus if you do a regex match, and call a sub that does a regex match, when that sub returns, your variables are still set as they were for the first match. They are dynamically scoped, as if they had an implicit ‘local’ at the start of the enclosing scope. Using these variables is not recommended in scripts when performance matters, as it causes Perl to slow down all regex matches in your entire script.Īll these variables are read-only, and persist until the next regex match is attempted. $` (dollar backtick) holds the part of the string before (to the left of) the regex match. $' (dollar followed by an apostrophe or single quote) holds the part of the string after (to the right of) the regex match. Since named groups are also numbered, you can use and for named groups, but you have to figure out the group’s number by yourself. Perl does not provide a way to get match positions of capturing groups by referencing their names. In Perl, you can use the m// operator to test if a regex can match a string, e.g.: if ($string =~ m/regex/) holds the text matched by the group “name”.

This in contrast with most other languages, where regular expressions are available as add-on libraries. Since CGI script basically is a text-processing script, Perl was and still is a natural choice.īecause of Perl’s focus on managing and mangling text, regular expression text patterns are an integral part of the Perl language. A CGI script is a small piece of software that generates a dynamic web page, based on a database and/or input from the person visiting the website. When the world wide web became popular, Perl became the de facto standard for creating CGI scripts.

Over the years, it has grown into a full-fledged programming language, keeping a strong focus on text processing. Perl was originally designed by Larry Wall as a flexible text-processing language. Perl’s Rich Support for Regular Expressions
