Skip to main content

Perl-style


The Perl programming language is exceptional at parsing strings by providing a comprehensive regular
expression language to the programmer. Rather than creating their own regular expression language, the
developers of PHP made the Perl regular expression syntax available to PHP users. The Perl-style regular
expression syntax was built from the POSIX regular expression syntax and thus hold many of the same
features. In fact, PHP programmers can use many of the same POSIX regular expression syntax when
using Perl-style regular expression syntax. The basic Perl-style regular expression syntax involves using
forward slashes (/ /) to identify the pattern that will be searched for: /mysql/ will find any string that
contains the pattern "mysql", /m+/ will find any string that contains the letter "m" followed by one or more
characters (mysql, mom, mudd, my, etc.) and /m{2,4}/ will find any string that contains the letter "m"
followed by 2 or 4 characters (mom, mysql, etc.). The Perl-style regular expressions are utilized in three
methods: Quantifiers, Modifiers and Metacharacters.

• Quantifiers - The quantifiers used in Perl-style regular expressions are identical to those used in
POSIX ERE's.

• Modifiers - These are specific commands that allow for a more defined search based on the
specific needs of that search. These commands work by being added to the standard Perl-style
regular expressions. The following is a list of the most common Perl-style modifiers:

   ô€‚ƒ i - performs a case insensitive search (ex. /mysql/i will find "mysql" and "MYSQL" or any
      other combination of upper and lower case characters).
   ô€‚ƒ g - finds all occurrences of the search pattern (ex. /iss/g will find 2 occurrences of "iss" in
      "Mississippi"). This is useful when performing a global search and replace.
   ô€‚ƒ m - performs the search based on individual lines in a multiple line string. For example, when
       using the characters ^ (which is for matching at the beginning of the string) or $ (which is for
       matching at the end of the string), the programmer can search a string with multiple lines as if
       they were individual lines. (ex. /^Thomas/ would not be matched against the following
       sentence but /^Thomas/m would be: "My mother went to the store.\nThomas went with her.")
   ô€‚ƒ x - this Perl-style modifier will ignore white space and comments within the regular
      expression.
   ô€‚ƒ U - this Perl-style modifier will stop the searching after the first occurrence of the pattern is
      found.

• Metacharacters - These are specific characters that are preceded by a backslash that symbolize a
special meaning for the character following. The following are a few of the metacharacters
associated with Perl-style regular expressions:

    ô€‚ƒ \A - matches patterns only at the beginning of the string
    ô€‚ƒ \b - matches a word boundary (ex. /\bis\b/ will find only occurrences of "is" but not words
        like "dish" or "mist", /is\b/ would find not only "is" but also "his" because the boundary is
        looking for the only "is" at the end of the word, ignoring what would be in front of it). \B
        ignores word boundaries.
    ô€‚ƒ \d - matches any numeric digit character. \D is the opposite matching any non-numeric
       character.
    ô€‚ƒ \s - matches a white space character. \S matches non-white space characters.
       Other metacharacters that do not require the backslash include:
    ô€‚ƒ $ - matches patterns at the end of the line
    ô€‚ƒ ^ - matches pattern at the beginning of the line
    ô€‚ƒ . - matches any pattern except for the new line
    ô€‚ƒ ( ) - encloses a character grouping

Comments

Popular posts from this blog

PHP INTRODUCTION

                     PHP  (recursive acronym for  PHP: Hypertext Preprocessor ) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML. PHP stands for  P HP:  H ypertext  P reprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) PHP is an open source software PHP is free to download and use Why PHP? PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is FREE to download from the official PHP resource:  www.php.net PHP is easy to learn and runs efficiently on the server side What can PHP do? Anything. PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynam

MySQL General Architecture

        MySQL operates in a networked environment using a client/server architecture. In other words, a central  program acts as a server, and various client programs connect to the server to make requests. A MySQL  installation has the following major components: MySQL Server, Client programs and MySQL non client  utilities.  MySQL Server MySQL Server, or mysqld, is the database server program. The server manages access to the actual  database (schema) on disk and in memory. MySQL Server is multi-threaded and supports many  simultaneous client connections. Clients can connect via several connection protocols. For managing  database contents, the MySQL server features a modular architecture that supports multiple storage engines  that handle different types of tables (for example, it supports both transactional and non-transactional  tables). Keep in mind the difference between a server and a host. The server is software (the MySQL server  program mysqld). Server characteristi