Regular expression almost on the programming language above have their own place, because recently in the source code of some foreign gods have used the regular expression, for regular expression, oneself also use not much, unavoidably feel jerky, so recently checked a lot of information, let oneself on regular expression have a little understanding.
1: Definition of regular expressions
When using the Pcre function, you need to enclose the pattern with a delimiter. Delimiters can be characters other than the following: letters or numbers, backslashes, white-space characters (Non-alphanumeric, Non-backslash, non-whitespace), frequently used separators are: slash (/, Forward slash), well (#,hash sign) and tilde (~,tilde). Here are some of the effective patterns
/foo bar/ #^[^0-9]$#+php+ %[a-za-z0-9_-]%
2: Special characters in regular expressions need to be escaped, that is, precede each special character with a backslash (\), the special characters are as follows
. : matches any single character except "\ n" \: Marks the next character as a special character, or a literal character, or a backward reference, or an octal escape character +: matches the preceding subexpression once or multiple times * : matches the preceding subexpression 0 or more times? : Matches the preceding subexpression 0 or one time []: Character set. Match any one of the characters {}: matches the determined n times (pattern): matches the pattern and gets the match ^: match thestarting position of the input string $: matches the end position of the input string -: typically used for [0-9], Represents any number in the range that matches 0 to 9 | : The representation or relationship also has >, <,
(?:p Attern): matches pattern, but does not capture content
3: Combining [], () and?: Parsing URLs
$pattern= ' ~http\://(?: [\w]*\.?] +)((?:/ [\w|\d]*) *) \? ((?: [\w|\d]*\=[\d|\w]*&?) *) ~x ';$str= "http://framework.easy.com/user/local?name=tom&age=10";Preg_match_all($pattern,$str,$matchs, Preg_set_order |preg_offset_capture);Echo"<pre>";Print_r($matchs);Echo"</pre>";/** * * Results **/Array( [0] = =Array ( [0] = =Array ( [0] = + http://framework.easy.com/user/local?name=tom&age=10[1] = 0 ) [1] = =Array ( [0] = Framework.easy.com [1] = 7 ) [2] = =Array ( [0] =/user/Local [1] = 25 ) [3] = =Array ( [0] = name=tom&age=10 [1] = 37 ) ))
Basic knowledge of regular expressions