With or internship day08

--- --- restore content begins

Today's practice regular expression:

 

Recommended 30 minutes of learning: http: //deerchao.net/tutorials/regex/regex-1.htm
competition website: https://alf.nu/RegexGolf

 

What are regular expressions?

Regular expressions are also used for text matching tool, but more accurately describe your needs better than a wildcard

 

\ d + is a simple code that represents the regular one or more digits of  2008 to comply with this rule, and A3 are not eligible (it contains non-numeric characters)

\ b a special code is a regular expression, a representative of the word beginning or end of   \ bhi \ b.

If you're looking for is a hi not far behind followed by a Lucy, you should use \ bhi \ b. * \ BLucy  \ b.

 

It is another special code that represents any character except newline. * The same is special code, but it is not representative of the character, not the location, but the number - it specifies the * content front can be repeated any time to make the whole expression matched. * Together means that does not contain newline characters in any number. Now . \ Bhi \ b * \ bLucy \ b meaning is quite clear: First, a word hi , then any number of any characters (but not a newline), the last word is Lucy

0 \ d \ d- \ d \ d \ d \ d \ d \ d \ d \ d represents a string like: 0 at the beginning, followed by two digits, followed by a hyphen "-", and finally 8 digital (that is, China's phone number, of course, this example only match the area code is three circumstances,

 

Figures that can appear on behalf of how many times can appear in front of

Expression: 0 \ d {2} - \ d {8} where \ behind D {2} ( {8}) specified in front \ d must be continuously repeated two times (8 times).

 

Now that you know the code has some special significance, such as the \ b, ., *, There \ d. In fact there are more special codes, such as \ s behalf any whitespace, including spaces, tabs character (Tab), line breaks. \ w represents a letter or number.

 

 

 When QQ number must be from 5 to 12 numbers, you may be used: ^ \ {D} $ 5,12

 

Character escape

If you want to find their own special code words, such as you find , or. *, There is a problem: you can not specify them, because they will be interpreted into other means. Then you have to use \ to cancel the special meaning of these characters. Therefore, you should use \. And \ *. Of course, to find \ itself, you have to use \\.

For example: deerchao \ .cn matching deerchao . CN, C: \\ Windows Match C: \ Windows, 2 \ ^ 8 match 2 ^ 8 (which is typically 8 th writing mode 2).

 

 

Character Classes

We can also easily specify a character range, like the meaning of [0-9] represent the d is exactly \ of

Digit, similarly [a-z0-9A-Z] is completely equivalent to \ w

 

Complex expressions: (? 0 \ D {2} [)? \ -] \ D {. 8}. Phone numbers several formats, like (010) 88886666, or 022-22334455 or 02912345678 etc.

Antisense (antisense capital is [^ this is to write anti inside, the beginning of what is written on the outside])

 

 

How should we do if you want to repeat a string?

You can use parentheses to specify the sub-expression (also called a packet),

 

 \ b \ w * q [^ u] \ w * \ b matching comprises not behind the letter u q letter word. But if do test (or you mentally alert enough to directly observe out), you will find that if q appear at the end of a word, then, like Iraq , Benq , this expression will be wrong.

--- end --- restore content

Guess you like

Origin www.cnblogs.com/Py-king/p/11763605.html