Preface:
Six months ago I have had regular expressions of interest in on-line to find a lot of information, read a lot of course, the last in the use of a regular expression tool RegexBuddy when he found the course very well written, it can be said that I have seen the best regular expression tutorial. As a result he would like to have been translated. The aspirations of the long holiday until May 1 this can be achieved, the results will have this article. This article on the name, "in layman's language" seems to have Taisu. But read the original text, only that "in layman's language" in order to correct the course to express my feelings, it can not escape the.
Jan Goyvaerts for this article was written by RegexBuddy course of the translation, the original author copyright of all, welcome to reprint. However, in order to respect the original author and translator of the work, please reference! Thanks!
What is a regular expression
Basically said, is a regular expression used to describe a certain number of text mode. Regex on behalf of the Regular Express. This article will be <<regex>> to indicate the specific section of the regular expression. A section of text is the most basic model, a simple match the same text.
Different regular expression engine
Regular expression engine is a regular expression processing software. Typically, the engine is a bigger part of the application. In the software world, different regular expressions are not compatible with each other. The present course will focus on the Perl 5 types of engines, engine because it is the most widely used engines. At the same time, we will also talk about some of the engine and other differences. Many modern engines are very similar, but not exactly the same. For example. NET regular library, JDK regular package.
Sign language
The most basic regular expression from a single text symbols. If <<a>>, it will match the first time in the string of characters "a". If the string of "Jack is a boy". "J" after "a" will be matched. And the second "a" will not be matched. Regular expressions can match the second "a", which tells you must be a regular expression engine from the first match of the beginning of local search. In a text editor, you can use the "Find Next." In the programming language, there will be a function can be used to make your first match back to the beginning of the location of the search.
A similar, <<cat>> will match "About cats and dogs" in the "cat". This is tantamount to tell regular expression engine to find a <<c>>, keep up with a <<a>>, a point with <<t>>.
Bearing in mind that regular expression engine is the default case-sensitive. Unless you tell the engine Ignore case, or else <<cat>> will not match the "Cat".
Special characters
The text characters, 11 characters were retained for special purposes. They are: [] \ ^ $. |? * + ()
These special characters are also known as the yuan characters.
If you would like regular expressions of these characters will be used for text characters, you need to use the backslash, "\" for their code (escape). For example, you want to match "1 +1 = 2", the right to expression <<1 \ +1 = 2>>.
It should be noted that, "<1 +1 = 2>> is a valid regular expression. However, it does not match the "1 +1 = 2" and the match will be "123 +111 = 234" "111 = 2." "+", Said a special meaning here (1st to repeat many times).
In the programming language, bearing in mind that some special characters will be dealing with the compiler, and then to the longer regular engine. Therefore, regular expressions <<1 \ + 2 = 2>> in C + + to write in "1 \ \ +1 = 2." In order to match the "C: \ temp", you should use regular expressions <<C:\\temp>>. In the C + +, the regular expression has been turned into "C: \ \ \ \ temp".