Original address: Http://javascript.info/tutorial/regexp-introductionBrief introductionRegular expressions have a very powerful function for string "Find" and "replace". In JS, it is integrated in the string method: Search, match, and replace.A regular expression, consisting of a pattern(matching rule) and a flags(modifier-optional).A basic
Regular expressions are detailed. Regular expressions in PHP (1) PHP inherits the consistent tradition of * NIX and fully supports the processing of regular expressions. Regular expressions provide an advanced, but not intuitive string matching and processing of regular expr
VBS Tutorial: regular expression syntax
Regular expression syntax
A regular expression is a text mode consisting of common characters (such as characters a to z) and special characters
is used, "$" will match the end of the absolute string instead of the newline character, which is turned on by default.
U
Greedy mode, similar to the role of question marks, the maximum match is greedy mode.
the common metacharacters
Code
Description
.
Match any character except newline (\r\n,\r,\n)
\w
Match letters or numbers or underscores or kanji
\s
Matches any
collection of atomsMatch any character except line break. Any character other than a line break\d matches any decimal number, i.e. [0-9]\d matches any non-decimal number, i.e. [^0-9]\s matches an invisible atom, i.e. [\f\n\r\t\v]\s matches a visible atom, i.e. [^\f\n\r\t\v]\w matches any number, letter, or underscore, i.e. [0-9a-za-z]W: matches any word character that includes an underscore. Similar but not equivalent to "[a-za-z0-9_]", where the "word" character uses the Unicode character set.
PHP Tutorial pcre Regular Expression Complete tutorialPredefined constants
Preg_pattern_order
The results are sorted by "rules", only for Preg_match_all, i.e. $matches[0] is the result of a complete rule, $matches [1] is the result of the first subgroup matchPreg_set_order:
The results are sorted by "set" only for Preg_match_all, that is, $matches[0] saves all
Php regular expressions are used to obtain all the URLs and link texts of a webpage. Php Tutorial regular expression get all web pages and link text $ urlwww.111cn.net; $ body @ file_get_contents ($ url); preg_match_all (href []? ([^] *) []? (. *) I, $ body, $ B php Tutorial
Special Charactersin regular style, some characters have special usage: [ \ ^ $ . | ? * + ( ).They are special because they are used to enhance the regular matching function. Don't try to memorize them, and when we've all used them, you can easily remember them.to use a special character as an ordinary identity, you must escape it . In other words, you need to precede the backslash.For example, we want to f
DFA engine they do not require backtracking (and therefore they never test the same characters two times), so the match is fast ! The DFA engine can also match the longest possible string. However, the DFA engine contains only a limited state, so it cannot match a pattern with a reverse reference, and no subexpression can be captured . Representative: awk,egrep,flex,lex,mysql,procmail
NFA non-deterministic Finite automaton is a finite automaton, and is divided into tra
modifierA regular may contain a modifier that can affect search results.There are 3 modifiers in JS:g: Find all results;I: result ignoring case;m: Multi-line matching mode;Modifier is placed after the parameter, such as:/.../g.A regular with no global modifier returns only the first matching value:1 alert ("123". Match (/\d/)) // ' 1 'If there is a global modifier, all matching values will be returned:1 a
The format of the string intercepted by php regular expression is
This is what it looks like
How can I intercept the contents in src = "", that is, the red part. Thank you for your guidance.
Reply to discussion (solution)
$s=txt;preg_match('/src="(.+?)"/i', $s, $m);echo $m[1];
$ S = How can I intercept the contents in src = "...", that is, the red part. Tuto
$string='April15,2003';$pattern='/(\w+)(\d+),(\d+)/i';$replacement='${1},${3}';echo preg_replace($pattern,$replacement,$string);?>
The result of this expression is april1,2003Cause: (\w+) can match April15 completely, but because (\d+) is behind (\w+), in order to be able to match defined rules, (\w+) matches April1, (\d+) matches 5You can change the expression to avoid this situation such as:$pattern = '/
Friendly reminder: This blog is involved in the content of the system practices involved in the implementation of Centos6.5, Gnu/linux referred to as linux,gnu/grep abbreviation for the grep,gnu/sed abbreviation for the Sed,gnu/gawk abbreviation for awk. ------------------------------------------------- Wedge ---------
In this case, the regular expression optimization, mainly for the current commonly used NFA pattern regular expressions, in detail can be referred to: regular expression matching parsing process analysis (regular
A regular expression is a logical formula for string operations. It uses predefined characters and combinations of these specific characters to form a "rule string ", this "rule string" is used to express a filtering logic for strings.Given a regular expression and another string, we can achieve the
NFA constructs a specific extension of a regular expression to achieve a successful match, it can capture the subexpression matching and matching reverse references. However, because of the traditional NFA backtracking, it can access the exact same state multiple times (if the state is reached through a different path). Therefore, at worst, it can perform very slowly. Because the traditional NFA accepts th
same.Reverse pre-search: "(? The concept of these two formats and forward pre-search is similar, the requirement for reverse pre-search is: "left side" of the gap, the two formats must be able to match and must not match the specified expression, rather than to judge the right. As with forward pre-search, they are an additional condition to the slot in which they do not match any characters.Example 5: Expression
As with the MySQL comprehensive optimization detailed in the previous writing, it is because such tools are widely used, so a comprehensive optimization strategy for such tools is a good deal, because whether you're a programmer in PHP, Perl, Python, C + +, C #, Java, and so on, You are very likely to use a tool such as MySQL, regular expressions.
Let's say something you may not know. Knowledge of regular
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.