Create a PHP dynamic web page to view regular expressions of instances
Source: Internet
Author: User
First, let's take a look at two special characters: '^' and '$'. they are used to identify The start and end of a string. The following example shows The difference: "^ ": match a string starting with "The"; "ofdespair $": match a string ending with "ofdespair". let's take a look at two special characters: '^' and '$' are used to identify the start and end of a string. the following examples illustrate the difference:
'^ The': matches a string starting with ';
'Of despair $': matches the string ending with 'of despair;
'^ Abc $': matches strings starting with abc and ending with abc. In fact, only abc matches;
'Notice': matches a string containing notice;
You can see that if you didn't use the two characters we mentioned (the last example), that is, the pattern (regular expression) can be displayed anywhere in the string to be tested, you didn't lock him to either side.
How many characters are there, '*', ', and '? They are used to represent the number or order of times a character can be displayed. their resolution performance: 'Zero or more ', 'one or more', and 'zero or one. 'Here are some examples:
'AB *': matches strings a and 0 or more B ('A', 'AB', 'abbb', etc .);
'AB': Same as above, but at least one B ('AB', 'abbb', etc .);
'AB? ': Matches 0 or a B;
'A? B $ ': match the string ending with one or zero a plus more than one B.
You can also limit the number of characters displayed in braces, such
'AB {2}': Match a and a with two B (one cannot be less) ('Abb ');
'AB {2,}': at least two more B ('abb', 'abbbb', etc .);
'AB {3, 5}': 2-5 B ('abbb', 'abbbb', or 'abbbb ').
You must also note that you must always specify (I. e, '{0, 2}', not '{, 2 }'). similarly, you must note that '*', ', and '? 'Resolution is the same as that for the next three categories, '{0,}', '{1,}', and '{0, 1 }'.
Put the target character of a certain number in parentheses, for example:
'A (bc) * ': matches 0 or a 'BC' behind ';
'A (bc) {} ': one to five 'BC .'
There is also a character '│ ', which is equivalent to OR control:
'Hi │ Hello': match a string containing 'hi' or 'hello;
'(B │ cd) ef': matches strings containing 'bef' or 'cdef;
'(A │ B) * C': match the string containing multiple (including 0) a or B, followed by a string of c;
A point ('.') can represent all single characters:
'A. [0-9] ': a. is followed by a character and a number (a string containing such a string will be matched and this bracket will be omitted later)
'^. {3} $': ends with three characters. the content enclosed in brackets only matches a single character.
'[AB]': Match a or B (same as 'a │ B );
'[A-d]': match a single character from 'A' to 'D' (same as 'a │ B │ c │ d' and '[abcd );
'^ [A-zA-Z]': match a string starting with a letter
'[0-9] %': matches a string that contains x %
', [A-zA-Z0-9] $': match a string ending with a comma plus a number or letter
You can also include the characters you don't want in brackets. you only need to apply '^' to the brackets to start with (I. e ., '% [^ a-zA-Z] %' matches a non-letter string with two percentage signs ).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service