Regular expressions in PHP for beginners II.

s numerical values ​​not In the last part, we discuss the basics of syntax and the simplest way to use regular expressions. Now let’s look at the syntax of Perl-compatible expressions.

We will also discuss other ways to use them. Everything we learn last time about POSIX expressions also applies to Perl, so we’ll just explain the differences and add a few new things.

Here you can find the first part of the series: Regular expressions in PHP for beginners I.
Perl-compatible expressions
The first and optically most significant difference from the POSIX standard is the ne to enclose the entire expression between separators . The separator can be any character except alphanumeric characters, whitespace characters and backslashes. Characters such as tc. are often us ‘~’. So instead we will write , or perhaps . The delimiter character must not be us inside an expression. If we still ne to include it in the expression, we have to add a backslash before it (of course, we must not forget the rules for writing strings

The backslash character has a wider

meaning in Perl-compatible expressions than in POSIX. We have already discuss one method of use in the previous article. If a backslash is follow by a non-alphanumeric character, the character is treat as an ordinary character (not a metacharacter). The second usage allows us to express non-printable characters in expressions. Here is an overview of the most us:

 

Expression modifiers represent perhaps

The biggest change from POSIX regular expressions. The list of modifiers is given after the expression itself (which is why the expression is also enclos in delimiters to make it clear where the expression ends and the modifiers begin), and these modifiers qatar phone number data directly affect some aspects of evaluation. So if we us the character as a separator  the whole expression would look like this: . Each modifier is represent by a single letter, see the table below. If we do not want to change the course of the evaluation, there is no ne to specify any mod

phone number data

modifier importance
‘i’ evaluation will not be case sensitive
‘m’ turns on multiline mode (metacharacters ‘^’and ‘$’then match the beginning and end of a line, not the beginning and end of a string)
‘s’ The dot ( ‘.’) metacharacter also matches line breaks (by default, it matches all characters except line breaks)
All whitespace characters in the expression except those inside. Enumerations) will be completely ignor, as well as all characters between. And including the nearest line break suitable for example. For user comments inside complex expressions.
‘e’ subexpressions replac by the function preg_replace()are evaluat as PHP code before being replac (we’ll look at this modifier in more detail in Substring Replacement )
‘S’ sets the parser to spend more time preprocessing this expression (can be worthwhile for complicat expressions that are us multiple times)
‘U’ changes the behavior of quantifiers so that they are not hungry (we will discuss hunger in more detail in the Subexpressions section )
Local use of modifiers
In some cases, we may want to change the base on your analytics behavior using modifiers for only a small part of the expression. Locally, we insert the modifier(s) directly into the syntax expression , and these changes take effect from the point cg leads of introduction. For example, the strings match i , but no longer . If a local modifier is given inside a subexpression.

Scroll to Top