日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python re

發(fā)布時(shí)間:2023/12/8 python 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python re 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Abstract(摘要)This document is an introductory tutorial to using regular expressions in Python with the re module. It provides a gentler introduction than the corresponding section in the Library Reference.本文是通過(guò)Python的 re 模塊來(lái)使用正則表達(dá)式的一個(gè)入門(mén)教程,和庫(kù)參考手冊(cè)的對(duì)應(yīng)章節(jié)相比,更為淺顯易懂、循序漸進(jìn)。This document is available from http://www.amk.ca/python/howto .本文可以從 http://www.amk.ca/python/howto 捕獲Contents(目錄)Contents Introduction(簡(jiǎn)介) Simple Patterns(簡(jiǎn)單模式) Matching Characters(字符匹配) Repeating Things(重復(fù)) Using Regular Expressions(使用正則表達(dá)式) Compiling Regular Expressions(編譯正則表達(dá)式) The Backslash Plague(反斜杠的麻煩) Performing Matches(執(zhí)行匹配) Module-Level Functions(模塊級(jí)函數(shù)) Compilation Flags(編譯標(biāo)志) More Pattern Power(更多模式功能) More Metacharacters(更多的元字符) Grouping(分組) Non-capturing and Named Groups(無(wú)捕獲組和命名組) Lookahead Assertions(前向界定符) Modifying Strings(修改字符串) Splitting Strings(將字符串分片) Search and Replace(搜索和替換) Common Problems(常見(jiàn)問(wèn)題) Use String Methods(使用字符串方式) match() versus search()(match() vs search()) Greedy versus Non-Greedy(貪婪 vs 不貪婪) Not Using re.VERBOSE(不用 re.VERBOSE) Feedback(反饋) About this document(關(guān)于本文檔)Introduction(簡(jiǎn)介)The re module was added in Python 1.5, and provides Perl-style regular expression patterns. Earlier versions of Python came with the regex module, which provides Emacs-style patterns. Emacs-style patterns are slightly less readable and don't provide as many features, so there's not much reason to use the regex module when writing new code, though you might encounter old code that uses it.Python 自1.5版本起增加了re 模塊,它提供 Perl 風(fēng)格的正則表達(dá)式模式。Python 1.5之前版本則是通過(guò) regex 模塊提供 Emecs 風(fēng)格的模式。Emacs 風(fēng)格模式可讀性稍差些,而且功能也不強(qiáng),因此編寫(xiě)新代碼時(shí)盡量不要再使用 regex 模塊,當(dāng)然偶爾你還是可能在老代碼里發(fā)現(xiàn)其蹤影。Regular expressions (or REs) are essentially a tiny, highly specialized programming language embedded inside Python and made available through the re module. Using this little language, you specify the rules for the set of possible strings that you want to match; this set might contain English sentences, or e-mail addresses, or TeX commands, or anything you like. You can then ask questions such as "Does this string match the pattern?", or "Is there a match for the pattern anywhere in this string?". You can also use REs to modify a string or to split it apart in various ways.就其本 質(zhì)而言,正則表達(dá)式(或 RE)是一種小型的、高度專(zhuān)業(yè)化的編程語(yǔ)言,(在Python中)它內(nèi)嵌在Python中,并通過(guò) re 模塊實(shí)現(xiàn)。使用這個(gè)小型語(yǔ)言,你可以為想要匹配的相應(yīng)字符串集指定規(guī)則;該字符串集可能包含英文語(yǔ)句、e-mail地址、TeX命令或任何你想搞定的東 西。然后你可以問(wèn)諸如“這個(gè)字符串匹配該模式嗎?”或“在這個(gè)字符串中是否有部分匹配該模式呢?”。你也可以使用 RE 以各種方式來(lái)修改或分割字符串。Regular expression patterns are compiled into a series of bytecodes which are then executed by a matching engine written in C. For advanced use, it may be necessary to pay careful attention to how the engine will execute a given RE, and write the RE in a certain way in order to produce bytecode that runs faster. Optimization isn't covered in this document, because it requires that you have a good understanding of the matching engine's internals.正則表達(dá)式模式被編譯成一系列的字節(jié)碼,然后由用 C 編寫(xiě)的匹配引擎執(zhí)行。在高級(jí)用法中,也許還要仔細(xì)留意引擎是如何執(zhí)行給定 RE ,如何以特定方式編寫(xiě) RE 以令生產(chǎn)的字節(jié)碼運(yùn)行速度更快。本文并不涉及優(yōu)化,因?yàn)槟且竽阋殉浞终莆樟似ヅ湟娴膬?nèi)部機(jī)制。The regular expression language is relatively small and restricted, so not all possible string processing tasks can be done using regular expressions. There are also tasks that can be done with regular expressions, but the expressions turn out to be very complicated. In these cases, you may be better off writing Python code to do the processing; while Python code will be slower than an elaborate regular expression, it will also probably be more understandable.正 則表達(dá)式語(yǔ)言相對(duì)小型和受限(功能有限),因此并非所有字符串處理都能用正則表達(dá)式完成。當(dāng)然也有些任務(wù)可以用正則表達(dá)式完成,不過(guò)最終表達(dá)式會(huì)變得異常 復(fù)雜。碰到這些情形時(shí),編寫(xiě) Python 代碼進(jìn)行處理可能反而更好;盡管 Python 代碼比一個(gè)精巧的正則表達(dá)式要慢些,但它更易理解。Simple Patterns(簡(jiǎn)單模式)We'll start by learning about the simplest possible regular expressions. Since regular expressions are used to operate on strings, we'll begin with the most common task: matching characters.我們將從最簡(jiǎn)單的正則表達(dá)式學(xué)習(xí)開(kāi)始。由于正則表達(dá)式常用于字符串操作,那我們就從最常見(jiàn)的任務(wù):字符匹配 下手。For a detailed explanation of the computer science underlying regular expressions (deterministic and non-deterministic finite automata), you can refer to almost any textbook on writing compilers.有關(guān)正則表達(dá)式底層的計(jì)算機(jī)科學(xué)上的詳細(xì)解釋(確定性和非確定性有限自動(dòng)機(jī)),你可以查閱編寫(xiě)編譯器相關(guān)的任何教科書(shū)。1. Matching Characters(字符匹配)Most letters and characters will simply match themselves. For example, the regular expression test will match the string "test" exactly. (You can enable a case-insensitive mode that would let this RE match "Test" or "TEST" as well; more about this later.)大多數(shù)字母和字符一般都會(huì)和自身匹配。例如,正則表達(dá)式 test 會(huì)和字符串“test”完全匹配。(你也可以使用大小寫(xiě)不敏感模式,它還能讓這個(gè) RE 匹配“Test”或“TEST”;稍后會(huì)有更多解釋。)There are exceptions to this rule; some characters are special, and don't match themselves. Instead, they signal that some out-of-the-ordinary thing should be matched, or they affect other portions of the RE by repeating them. Much of this document is devoted to discussing various metacharacters and what they do.這個(gè)規(guī)則當(dāng)然會(huì)有例外;有些字符比較特殊,它們和自身并不匹配,而是會(huì)表明應(yīng)和一些特殊的東西匹配,或者它們會(huì)影響到 RE 其它部分的重復(fù)次數(shù)。本文很大篇幅專(zhuān)門(mén)討論了各種元字符及其作用。Here's a complete list of the metacharacters; their meanings will be discussed in the rest of this HOWTO.這里有一個(gè)元字符的完整列表;其含義會(huì)在本指南余下部分進(jìn)行討論。. ^ $ * + ? { [ ] \ | ( )The first metacharacters we'll look at are "[" and "]". They're used for specifying a character class, which is a set of characters that you wish to match. Characters can be listed individually, or a range of characters can be indicated by giving two characters and separating them by a "-". For example, [abc] will match any of the characters "a", "b", or "c"; this is the same as [a-c], which uses a range to express the same set of characters. If you wanted to match only lowercase letters, your RE would be [a-z].我們首先考察的元字符是 "[" 和 "]"。 它們常用來(lái)指定一個(gè)字符類(lèi)別,所謂字符類(lèi)別就是你想匹配的一個(gè)字符集。字符可以單個(gè)列出,也可以用“-”號(hào)分隔的兩個(gè)給定字符來(lái)表示一個(gè)字符區(qū)間。例如, [abc] 將匹配"a", "b", 或 "c"中的任意一個(gè)字符;也可以用區(qū)間[a-c]來(lái)表示同一字符集,和前者效果一致。如果你只想匹配小寫(xiě)字母,那么 RE 應(yīng)寫(xiě)成 [a-z]。Metacharacters are not active inside classes. For example, [akm$] will match any of the characters "a", "k", "m", or "$"; "$" is usually a metacharacter, but inside a character class it's stripped of its special nature.元字符在類(lèi)別里并不起作用。例如,[akm$]將匹配字符"a", "k", "m", 或 "$" 中的任意一個(gè);"$"通常用作元字符,但在字符類(lèi)別里,其特性被除去,恢復(fù)成普通字符。You can match the characters not within a range by complementing the set. This is indicated by including a "" as the first character of the class; `"" elsewhere will simply match the ""` character. For example, [5] will match any character except "5".你可以用補(bǔ)集來(lái)匹配不在區(qū)間范圍內(nèi)的字符。其做法是把"^"作為類(lèi)別的首個(gè)字符;其它地方的"^"只會(huì)簡(jiǎn)單匹配 "^" 字符本身。例如,[^5] 將匹配除 "5" 之外的任意字符。Perhaps the most important metacharacter is the backslash, "\". As in Python string literals, the backslash can be followed by various characters to signal various special sequences. It's also used to escape all the metacharacters so you can still match them in patterns; for example, if you need to match a "[" or "\", you can precede them with a backslash to remove their special meaning: \[ or \\.也 許最重要的元字符是反斜杠"\"。 做為 Python 中的字符串字母,反斜杠后面可以加不同的字符以表示不同特殊意義。它也可以用于取消所有的元字符,這樣你就可以在模式中匹配它們了。舉個(gè)例子,如果你需要 匹配字符 "[" 或 "\",你可以在它們之前用反斜杠來(lái)取消它們的特殊意義: \[ 或 \\。Some of the special sequences beginning with "\" represent predefined sets of characters that are often useful, such as the set of digits, the set of letters, or the set of anything that isn't whitespace. The following predefined special sequences are available:一些用 "\" 開(kāi)始的特殊字符所表示的預(yù)定義字符集通常是很有用的,象數(shù)字集,字母集,或其它非空字符集。下列是可用的預(yù)設(shè)特殊字符:\d Matches any decimal digit; this is equivalent to the class [0-9]. 匹配任何十進(jìn)制數(shù);它相當(dāng)于類(lèi) [0-9]。 \D Matches any non-digit character; this is equivalent to the class [^0-9]. 匹配任何非數(shù)字字符;它相當(dāng)于類(lèi) [^0-9]。 \s Matches any whitespace character; this is equivalent to the class [ \t\n\r\f\v]. 匹配任何空白字符;它相當(dāng)于類(lèi) [ \t\n\r\f\v]。 \S Matches any non-whitespace character; this is equivalent to the class [^ \t\n\r\f\v]. 匹配任何非空白字符;它相當(dāng)于類(lèi) [^ \t\n\r\f\v]。 \w Matches any alphanumeric character; this is equivalent to the class [a-zA-Z0-9_]. 匹配任何字母數(shù)字字符;它相當(dāng)于類(lèi) [a-zA-Z0-9_]。 \W Matches any non-alphanumeric character; this is equivalent to the class [^a-zA-Z0-9_]. 匹配任何非字母數(shù)字字符;它相當(dāng)于類(lèi) [^a-zA-Z0-9_]。 These sequences can be included inside a character class. For example, [\s,.] is a character class that will match any whitespace character, or "," or ".".這樣特殊字符都可以包含在一個(gè)字符類(lèi)中。如,[\s,.]字符類(lèi)將匹配任何空白字符或","或"."。The final metacharacter in this section is .. It matches anything except a newline character, and there's an alternate mode (re.DOTALL) where it will match even a newline. "." is often used where you want to match any character.本節(jié)最后一個(gè)元字符是 . 。它匹配除了換行字符外的任何字符,在 alternate 模式(re.DOTALL)下它甚至可以匹配換行。"." 通常被用于你想匹配“任何字符”的地方。2. Repeating Things(重復(fù))Being able to match varying sets of characters is the first thing regular expressions can do that isn't already possible with the methods available on strings. However, if that was the only additional capability of regexes, they wouldn't be much of an advance. Another capability is that you can specify that portions of the RE must be repeated a certain number of times.正則表達(dá)式第一件能做的事是能夠匹配不定長(zhǎng)的字符集,而這是其它能作用在字符串上的方法所不能做到的。 不過(guò),如果那是正則表達(dá)式唯一的附加功能的話(huà),那么它們也就不那么優(yōu)秀了。它們的另一個(gè)功能就是你可以指定正則表達(dá)式的一部分的重復(fù)次數(shù)。The first metacharacter for repeating things that we'll look at is *. * doesn't match the literal character "*"; instead, it specifies that the previous character can be matched zero or more times, instead of exactly once.我們討論的第一個(gè)重復(fù)功能的元字符是 *。* 并不匹配字母字符 "*";相反,它指定前一個(gè)字符可以被匹配零次或更多次,而不是只有一次。For example, ca*t will match "ct" (0 "a"characters), "cat" (1 "a"), "caaat" (3 "a"characters), and so forth. The RE engine has various internal limitations stemming from the size of C's int type, that will prevent it from matching over 2 billion "a" characters; you probably don't have enough memory to construct a string that large, so you shouldn't run into that limit.舉個(gè)例子, ca*t 將匹配 "ct" (0 個(gè) "a" 字符), "cat" (1 個(gè) "a"), "caaat" (3 個(gè) "a" 字符)等等。RE 引擎有各種來(lái)自 C 的整數(shù)類(lèi)型大小的內(nèi)部限制,以防止它匹配超過(guò)2億個(gè) "a" 字符;你也許沒(méi)有足夠的內(nèi)存去建造那么大的字符串,所以將不會(huì)累計(jì)到那個(gè)限制。Repetitions such as * are greedy; when repeating a RE, the matching engine will try to repeat it as many times as possible. If later portions of the pattern don't match, the matching engine will then back up and try again with few repetitions.象 * 這樣地重復(fù)是“貪婪的”;當(dāng)重復(fù)一個(gè) RE 時(shí),匹配引擎會(huì)試著重復(fù)盡可能多的次數(shù)。如果模式的后面部分沒(méi)有被匹配,匹配引擎將退回并再次嘗試更小的重復(fù)。A step-by-step example will make this more obvious. Let's consider the expression a[bcd]*b. This matches the letter "a", zero or more letters from the class [bcd], and finally ends with a "b". Now imagine matching this RE against the string "abcbd".一步步的示例可以使它更加清晰。讓我們考慮表達(dá)式 a[bcd]*b。它匹配字母 "a",零個(gè)或更多個(gè)來(lái)自類(lèi) [bcd]中的字母,最后以 "b" 結(jié)尾。現(xiàn)在想一想該 RE 對(duì)字符串 "abcbd" 的匹配。StepMatchedExplanation1aThe a in the RE matches.a 匹配模式2abcbdThe engine matches [bcd]*, going as far as it can, which is to the end of the string.引擎匹配 [bcd]*,并盡其所能匹配到字符串的結(jié)尾3FailureThe engine tries to match b, but the current position is at the end of the string, so it fails.引擎嘗試匹配 b,但當(dāng)前位置已經(jīng)是字符的最后了,所以失敗4abcbBack up, so that [bcd]* matches one less character.退回,[bcd]*嘗試少匹配一個(gè)字符。5FailureTry b again, but the current position is at the last character, which is a "d".再次嘗次b,但在當(dāng)前最后一位字符是"d"。6abcBack up again, so that [bcd]* is only matching "bc".再次退回,[bcd]*只匹配 "bc"。7abcbTry b again. This time but the character at the current position is "b", so it succeeds.再次嘗試 b ,這次當(dāng)前位上的字符正好是 "b"The end of the RE has now been reached, and it has matched "abcb". This demonstrates how the matching engine goes as far as it can at first, and if no match is found it will then progressively back up and retry the rest of the RE again and again. It will back up until it has tried zero matches for [bcd]*, and if that subsequently fails, the engine will conclude that the string doesn't match the RE at all.RE 的結(jié)尾部分現(xiàn)在可以到達(dá)了,它匹配 "abcb"。這證明了匹配引擎一開(kāi)始會(huì)盡其所能進(jìn)行匹配,如果沒(méi)有匹配然后就逐步退回并反復(fù)嘗試 RE 剩下來(lái)的部分。直到它退回嘗試匹配 [bcd] 到零次為止,如果隨后還是失敗,那么引擎就會(huì)認(rèn)為該字符串根本無(wú)法匹配 RE 。Another repeating metacharacter is +, which matches one or more times. Pay careful attention to the difference between * and +; * matches zero or more times, so whatever's being repeated may not be present at all, while + requires at least one occurrence. To use a similar example, ca+t will match "cat" (1 "a"), "caaat" (3 "a"'s), but won't match "ct".另 一個(gè)重復(fù)元字符是 +,表示匹配一或更多次。請(qǐng)注意 * 和 + 之間的不同;* 匹配零或更多次,所以根本就可以不出現(xiàn),而 + 則要求至少出現(xiàn)一次。用同一個(gè)例子,ca+t 就可以匹配 "cat" (1 個(gè) "a"), "caaat" (3 個(gè) "a"), 但不能匹配 "ct"。There are two more repeating qualifiers. The question mark character, ?, matches either once or zero times; you can think of it as marking something as being optional. For example, home-?brew matches either "homebrew" or "home-brew".還有更多的限定符。問(wèn)號(hào) ? 匹配一次或零次;你可以認(rèn)為它用于標(biāo)識(shí)某事物是可選的。例如:home-?brew 匹配 "homebrew" 或 "home-brew"。The most complicated repeated qualifier is {m,n}, where m and n are decimal integers. This qualifier means there must be at least m repetitions, and at most n. For example, a/{1,3}b will match "a/b", "a//b", and "a///b". It won't match "ab", which has no slashes, or "ab", which has four.最復(fù)雜的重復(fù)限定符是 {m,n},其中 m 和 n 是十進(jìn)制整數(shù)。該限定符的意思是至少有 m 個(gè)重復(fù),至多到 n 個(gè)重復(fù)。舉個(gè)例子,a/{1,3}b 將匹配 "a/b","a//b" 和 "a///b"。它不能匹配 "ab" 因?yàn)闆](méi)有斜杠,也不能匹配 "ab" ,因?yàn)橛兴膫€(gè)。You can omit either m or n; in that case, a reasonable value is assumed for the missing value. Omitting m is interpreted as a lower limit of 0, while omitting n results in an upper bound of infinity -- actually, the 2 billion limit mentioned earlier, but that might as well be infinity.你可以忽略 m 或 n;因?yàn)闀?huì)為缺失的值假設(shè)一個(gè)合理的值。忽略 m 會(huì)認(rèn)為下邊界是 0,而忽略 n 的結(jié)果將是上邊界為無(wú)窮大 -- 實(shí)際上是先前我們提到的 2 兆,但這也許同無(wú)窮大一樣。Readers of a reductionist bent may notice that the three other qualifiers can all be expressed using this notation. {0,} is the same as *, {1,} is equivalent to +, and {0,1} is the same as ?. It's better to use *, +, or ? when you can, simply because they're shorter and easier to read.細(xì)心的讀者也許注意到其他三個(gè)限定符都可以用這樣方式來(lái)表示。 {0,} 等同于 *,{1,} 等同于 +,而{0,1}則與 ? 相同。如果可以的話(huà),最好使用 *,+,或?。很簡(jiǎn)單因?yàn)樗鼈兏桃苍偃菀锥sing Regular Expressions(使用正則表達(dá)式)Now that we've looked at some simple regular expressions, how do we actually use them in Python? The re module provides an interface to the regular expression engine, allowing you to compile REs into objects and then perform matches with them.現(xiàn)在我們已經(jīng)看了一些簡(jiǎn)單的正則表達(dá)式,那么我們實(shí)際在 Python 中是如何使用它們的呢? re 模塊提供了一個(gè)正則表達(dá)式引擎的接口,可以讓你將 REs 編譯成對(duì)象并用它們來(lái)進(jìn)行匹配。1. Compiling Regular Expressions(編譯正則表達(dá)式)Regular expressions are compiled into RegexObject instances, which have methods for various operations such as searching for pattern matches or performing string substitutions.正則表達(dá)式被編譯成 RegexObject 實(shí)例,可以為不同的操作提供方法,如模式匹配搜索或字符串替換。Toggle line numbersToggle line numbersToggle line numbers 1 >>> import re 2 >>> p = re.compile('ab*') 3 >>> print p 4 re.compile() also accepts an optional flags argument, used to enable various special features and syntax variations. We'll go over the available settings later, but for now a single example will do:re.compile() 也接受可選的標(biāo)志參數(shù),常用來(lái)實(shí)現(xiàn)不同的特殊功能和語(yǔ)法變更。我們稍后將查看所有可用的設(shè)置,但現(xiàn)在只舉一個(gè)例子:Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('ab*', re.IGNORECASE)The RE is passed to re.compile() as a string. REs are handled as strings because regular expressions aren't part of the core Python language, and no special syntax was created for expressing them. (There are applications that don't need REs at all, so there's no need to bloat the language specification by including them.) Instead, the re module is simply a C extension module included with Python, just like the socket or zlib module.RE 被做為一個(gè)字符串發(fā)送給 re.compile()。REs 被處理成字符串是因?yàn)檎齽t表達(dá)式不是 Python 語(yǔ)言的核心部分,也沒(méi)有為它創(chuàng)建特定的語(yǔ)法。(應(yīng)用程序根本就不需要 REs,因此沒(méi)必要包含它們?nèi)ナ拐Z(yǔ)言說(shuō)明變得臃腫不堪。)而 re 模塊則只是以一個(gè) C 擴(kuò)展模塊的形式來(lái)被 Python 包含,就象 socket 或 zlib 模塊一樣。Putting REs in strings keeps the Python language simpler, but has one disadvantage which is the topic of the next section.將 REs 作為字符串以保證 Python 語(yǔ)言的簡(jiǎn)潔,但這樣帶來(lái)的一個(gè)麻煩就是象下節(jié)標(biāo)題所講的。2. The Backslash Plague(反斜杠的麻煩)As stated earlier, regular expressions use the backslash character ("\") to indicate special forms or to allow special characters to be used without invoking their special meaning. This conflicts with Python's usage of the same character for the same purpose in string literals.在早期規(guī)定中,正則表達(dá)式用反斜杠字符 ("\") 來(lái)表示特殊格式或允許使用特殊字符而不調(diào)用它的特殊用法。這就與 Python 在字符串中的那些起相同作用的相同字符產(chǎn)生了沖突。Let's say you want to write a RE that matches the string "\section", which might be found in a LATEX file. To figure out what to write in the program code, start with the desired string to be matched. Next, you must escape any backslashes and other metacharacters by preceding them with a backslash, resulting in the string "\\section". The resulting string that must be passed to re.compile() must be \\section. However, to express this as a Python string literal, both backslashes must be escaped again.讓我們舉例說(shuō)明,你想寫(xiě)一個(gè) RE 以匹配字符串 "\section",可能是在一個(gè) LATEX 文件查找。為了要在程序代碼中判斷,首先要寫(xiě)出想要匹配的字符串。接下來(lái)你需要在所有反斜杠和元字符前加反斜杠來(lái)取消其特殊意義。Characters(字符)Stage(階段)\sectionText string to be matched(要匹配的字符串)\\sectionEscaped backslash for re.compile(為 re.compile 取消反斜杠的特殊意義)"\\\\section"Escaped backslashes for a string literal(為字符串取消反斜杠)In short, to match a literal backslash, one has to write '\\\\' as the RE string, because the regular expression must be "\\", and each backslash must be expressed as "\\" inside a regular Python string literal. In REs that feature backslashes repeatedly, this leads to lots of repeated backslashes and makes the resulting strings difficult to understand.簡(jiǎn) 單地說(shuō),為了匹配一個(gè)反斜杠,不得不在 RE 字符串中寫(xiě) '\\\\',因?yàn)檎齽t表達(dá)式中必須是 "\\",而每個(gè)反斜杠按 Python 字符串字母表示的常規(guī)必須表示成 "\\"。在 REs 中反斜杠的這個(gè)重復(fù)特性會(huì)導(dǎo)致大量重復(fù)的反斜杠,而且所生成的字符串也很難懂。The solution is to use Python's raw string notation for regular expressions; backslashes are not handled in any special way in a string literal prefixed with "r", so r"\n" is a two-character string containing "\" and "n", while "\n" is a one-character string containing a newline. Frequently regular expressions will be expressed in Python code using this raw string notation.解 決的辦法就是為正則表達(dá)式使用 Python 的 raw 字符串表示;在字符串前加個(gè) "r" 反斜杠就不會(huì)被任何特殊方式處理,所以 r"\n" 就是包含"\" 和 "n" 的兩個(gè)字符,而 "\n" 則是一個(gè)字符,表示一個(gè)換行。正則表達(dá)式通常在 Python 代碼中都是用這種 raw 字符串表示。Regular String(常規(guī)字符串)Raw string(Raw 字符串)"ab*"r"ab*""\\\\section"r"\\section""\\w+\\s+\\1"r"\w+\s+\1"3. Performing Matches(執(zhí)行匹配)Once you have an object representing a compiled regular expression, what do you do with it? RegexObject instances have several methods and attributes. Only the most significant ones will be covered here; consult the Library Reference for a complete listing.一旦你有了已經(jīng)編譯了的正則表達(dá)式的對(duì)象,你要用它做什么呢?RegexObject 實(shí)例有一些方法和屬性。這里只顯示了最重要的幾個(gè),如果要看完整的列表請(qǐng)查閱 Library Refference。Method/Attribute(方法/屬性)Purpose(作用)match()Determine if the RE matches at the beginning of the string.決定 RE 是否在字符串剛開(kāi)始的位置匹配search()Scan through a string, looking for any location where this RE matches.掃描字符串,找到這個(gè) RE 匹配的位置findall()Find all substrings where the RE matches, and returns them as a list.找到 RE 匹配的所有子串,并把它們作為一個(gè)列表返回finditer()Find all substrings where the RE matches, and returns them as an iterator.找到 RE 匹配的所有子串,并把它們作為一個(gè)迭代器返回match() and search() return None if no match can be found. If they're successful, a MatchObject instance is returned, containing information about the match: where it starts and ends, the substring it matched, and more.如果沒(méi)有匹配到的話(huà),match() 和 search() 將返回 None。如果成功的話(huà),就會(huì)返回一個(gè) MatchObject 實(shí)例,其中有這次匹配的信息:它是從哪里開(kāi)始和結(jié)束,它所匹配的子串等等。You can learn about this by interactively experimenting with the re module. If you have Tkinter available, you may also want to look at Tools/scripts/redemo.py, a demonstration program included with the Python distribution. It allows you to enter REs and strings, and displays whether the RE matches or fails. redemo.py can be quite useful when trying to debug a complicated RE. Phil Schwartz's Kodos is also an interactive tool for developing and testing RE patterns. This HOWTO will use the standard Python interpreter for its examples.你可以用采用人機(jī)對(duì)話(huà)并用 re 模塊實(shí)驗(yàn)的方式來(lái)學(xué)習(xí)它。如果你有 Tkinter 的話(huà),你也許可以考慮參考一下 Tools/scripts/redemo.py,一個(gè)包含在 Python 發(fā)行版里的示范程序。First, run the Python interpreter, import the re module, and compile a RE:首先,運(yùn)行 Python 解釋器,導(dǎo)入 re 模塊并編譯一個(gè) RE:Toggle line numbersToggle line numbersToggle line numbers 1 Python 2.2.2 (#1, Feb 10 2003, 12:57:01) 2 >>> import re 3 >>> p = re.compile('[a-z]+') 4 >>> p 5 <_sre sre_pattern="" object="" at="" 80c3c28="">ERROR: EOF in multi-line statementNow, you can try matching various strings against the RE [a-z]+. An empty string shouldn't match at all, since + means 'one or more repetitions'. match() should return None in this case, which will cause the interpreter to print no output. You can explicitly print the result of match() to make this clear.現(xiàn) 在,你可以試著用 RE 的 [a-z]+ 去匹配不同的字符串。一個(gè)空字符串將根本不能匹配,因?yàn)?+ 的意思是 “一個(gè)或更多的重復(fù)次數(shù)”。 在這種情況下 match() 將返回 None,因?yàn)樗菇忉屍鳑](méi)有輸出。你可以明確地打印出 match() 的結(jié)果來(lái)弄清這一點(diǎn)。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p.match("") 2 >>> print p.match("") 3 NoneNow, let's try it on a string that it should match, such as "tempo". In this case, match() will return a MatchObject, so you should store the result in a variable for later use.現(xiàn)在,讓我們?cè)囍盟鼇?lái)匹配一個(gè)字符串,如 "tempo"。這時(shí),match() 將返回一個(gè) MatchObject。因此你可以將結(jié)果保存在變量里以便后面使用。Toggle line numbersToggle line numbersToggle line numbers 1 >>> m = p.match( 'tempo') 2 >>> print m 3 <_sre sre_match="" object="" at="" 80c4f68="">Now you can query the MatchObject for information about the matching string. MatchObject instances also have several methods and attributes; the most important ones are:現(xiàn)在你可以查詢(xún) MatchObject 關(guān)于匹配字符串的相關(guān)信息了。MatchObject 實(shí)例也有幾個(gè)方法和屬性;最重要的那些如下所示:Method/Attribute(方法/屬性)Purpose(作用)group()Return the string matched by the RE返回被 RE 匹配的字符串start()Return the starting position of the match返回匹配開(kāi)始的位置end()Return the ending position of the match返回匹配結(jié)束的位置span()Return a tuple containing the (start, end) positions of the match返回一個(gè)元組包含匹配 (開(kāi)始,結(jié)束) 的位置Trying these methods will soon clarify their meaning:試試這些方法不久就會(huì)清楚它們的作用了:Toggle line numbersToggle line numbersToggle line numbers 1 >>> m.group() 2 'tempo' 3 >>> m.start(), m.end() 4 (0, 5) 5 >>> m.span() 6 (0, 5)group() returns the substring that was matched by the RE. start() and end() return the starting and ending index of the match. span() returns both start and end indexes in a single tuple. Since the match method only checks if the RE matches at the start of a string, start() will always be zero. However, the search method of RegexObject instances scans through the string, so the match may not start at zero in that case.group() 返回 RE 匹配的子串。start() 和 end() 返回匹配開(kāi)始和結(jié)束時(shí)的索引。span() 則用單個(gè)元組把開(kāi)始和結(jié)束時(shí)的索引一起返回。因?yàn)槠ヅ浞椒z查到如果 RE 在字符串開(kāi)始處開(kāi)始匹配,那么 start() 將總是為零。然而, RegexObject 實(shí)例的 search 方法掃描下面的字符串的話(huà),在這種情況下,匹配開(kāi)始的位置就也許不是零了。Toggle line numbersToggle line numbersToggle line numbers 1 >>> print p.match('::: message') 2 None 3 >>> m = p.search('::: message') ; print m 4 5 >>> m.group() 6 'message' 7 >>> m.span() 8 (4, 11)In actual programs, the most common style is to store the MatchObject in a variable, and then check if it was None. This usually looks like:在實(shí)際程序中,最常見(jiàn)的作法是將 MatchObject 保存在一個(gè)變量里,然后檢查它是否為 None,通常如下所示:Toggle line numbersToggle line numbersToggle line numbers 1 p = re.compile( ... ) 2 m = p.match( 'string goes here' ) 3 if m: 4 print 'Match found: ', m.group() 5 else: 6 print 'No match'Two RegexObject methods return all of the matches for a pattern. findall() returns a list of matching strings:兩個(gè) RegexObject 方法返回所有匹配模式的子串。findall()返回一個(gè)匹配字符串列表:Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('\d+') 2 >>> p.findall('12 drummers drumming, 11 pipers piping, 10 lords a-leaping') 3 ['12', '11', '10']findall() has to create the entire list before it can be returned as the result. In Python 2.2, the finditer() method is also available, returning a sequence of MatchObject instances as an iterator.findall() 在它返回結(jié)果時(shí)不得不創(chuàng)建一個(gè)列表。在 Python 2.2中,也可以用 finditer() 方法。Toggle line numbersToggle line numbersToggle line numbers 1 >>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...') 2 >>> iterator 3 4 >>> for match in iterator: 5 ... print match.span() 6 ... 7 (0, 2) 8 (22, 24) 9 (29, 31)4. Module-Level Functions(模塊級(jí)函數(shù))You don't have to produce a RegexObject and call its methods; the re module also provides top-level functions called match(), search(), sub(), and so forth. These functions take the same arguments as the corresponding RegexObject method, with the RE string added as the first argument, and still return either None or a MatchObject instance.你不一定要產(chǎn)生一個(gè) RegexObject 對(duì)象然后再調(diào)用它的方法;re 模塊也提供了頂級(jí)函數(shù)調(diào)用如 match()、search()、sub() 等等。這些函數(shù)使用 RE 字符串作為第一個(gè)參數(shù),而后面的參數(shù)則與相應(yīng) RegexObject 的方法參數(shù)相同,返回則要么是 None 要么就是一個(gè) MatchObject 的實(shí)例。Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.match(r'From\s+', 'Fromage amk') 2 None 3 >>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998') 4 Under the hood, these functions simply produce a RegexObject for you and call the appropriate method on it. They also store the compiled object in a cache, so future calls using the same RE are faster.Under the hood, 這些函數(shù)簡(jiǎn)單地產(chǎn)生一個(gè) RegexOject 并在其上調(diào)用相應(yīng)的方法。它們也在緩存里保存編譯后的對(duì)象,因此在將來(lái)調(diào)用用到相同 RE 時(shí)就會(huì)更快。Should you use these module-level functions, or should you get the RegexObject and call its methods yourself? That choice depends on how frequently the RE will be used, and on your personal coding style. If a RE is being used at only one point in the code, then the module functions are probably more convenient. If a program contains a lot of regular expressions, or re-uses the same ones in several locations, then it might be worthwhile to collect all the definitions in one place, in a section of code that compiles all the REs ahead of time. To take an example from the standard library, here's an extract from xmllib.py: 你將使用這些模塊級(jí)函數(shù),還是先得到一個(gè) RegexObject 再調(diào)用它的方法呢?如何選擇依賴(lài)于怎樣用 RE 更有效率以及你個(gè)人編碼風(fēng)格。如果一個(gè) RE 在代碼中只做用一次的話(huà),那么模塊級(jí)函數(shù)也許更方便。如果程序包含很多的正則表達(dá)式,或在多處復(fù)用同一個(gè)的話(huà),那么將全部定義放在一起,在一段代碼中提前 編譯所有的 REs 更有用。從標(biāo)準(zhǔn)庫(kù)中看一個(gè)例子,這是從 xmllib.py 文件中提取出來(lái)的:Toggle line numbersToggle line numbersToggle line numbers 1 ref = re.compile( ... ) 2 entityref = re.compile( ... ) 3 charref = re.compile( ... ) 4 starttagopen = re.compile( ... )I generally prefer to work with the compiled object, even for one-time uses, but few people will be as much of a purist about this as I am.我通常更喜歡使用編譯對(duì)象,甚至它只用一次,but few people will be as much of a purist about this as I am。5. Compilation Flags(編譯標(biāo)志)Compilation flags let you modify some aspects of how regular expressions work. Flags are available in the re module under two names, a long name such as IGNORECASE, and a short, one-letter form such as I. (If you're familiar with Perl's pattern modifiers, the one-letter forms use the same letters; the short form of re.VERBOSE is re.X, for example.) Multiple flags can be specified by bitwise OR-ing them; re.I | re.M sets both the I and M flags, for example.編 譯標(biāo)志讓你可以修改正則表達(dá)式的一些運(yùn)行方式。在 re 模塊中標(biāo)志可以使用兩個(gè)名字,一個(gè)是全名如 IGNORECASE,一個(gè)是縮寫(xiě),一字母形式如 I。(如果你熟悉 Perl 的模式修改,一字母形式使用同樣的字母;例如 re.VERBOSE的縮寫(xiě)形式是 re.X。)多個(gè)標(biāo)志可以通過(guò)按位 OR-ing 它們來(lái)指定。如 re.I | re.M 被設(shè)置成 I 和 M 標(biāo)志:Here's a table of the available flags, followed by a more detailed explanation of each one.這有個(gè)可用標(biāo)志表,對(duì)每個(gè)標(biāo)志后面都有詳細(xì)的說(shuō)明。Flag(標(biāo)志)Meaning(含義)DOTALL, SMake . match any character, including newlines使 . 匹配包括換行在內(nèi)的所有字符IGNORECASE, IDo case-insensitive matches使匹配對(duì)大小寫(xiě)不敏感LOCALE, LDo a locale-aware match做本地化識(shí)別(locale-aware)匹配MULTILINE, MMulti-line matching, affecting and $[[BR]]多行匹配,影響 和 $VERBOSE, XEnable verbose REs, which can be organized more cleanly and understandably.能夠使用 REs 的 verbose 狀態(tài),使之被組織得更清晰易懂IIGNORECASE Perform case-insensitive matching; character class and literal strings will match letters by ignoring case. For example, [A-Z] will match lowercase letters, too, and Spam will match "Spam", "spam", or "spAM". This lowercasing doesn't take the current locale into account; it will if you also set the LOCALE flag. 使匹配對(duì)大小寫(xiě)不敏感;字符類(lèi)和字符串匹配字母時(shí)忽略大小寫(xiě)。舉個(gè)例子,[A-Z]也可以匹配小寫(xiě)字母,Spam 可以匹配 "Spam", "spam", 或 "spAM"。這個(gè)小寫(xiě)字母并不考慮當(dāng)前位置。 LLOCALE Make \w, \W, \b, and \B, dependent on the current locale. 影響 \w, \W, \b, 和 \B,這取決于當(dāng)前的本地化設(shè)置。 Locales are a feature of the C library intended to help in writing programs that take account of language differences. For example, if you're processing French text, you'd want to be able to write \w+ to match words, but \w only matches the character class [A-Za-z]; it won't match "é" or "?". If your system is configured properly and a French locale is selected, certain C functions will tell the program that "é" should also be considered a letter. Setting the LOCALE flag when compiling a regular expression will cause the resulting compiled object to use these C functions for \w; this is slower, but also enables \w+ to match French words as you'd expect. locales 是 C 語(yǔ)言庫(kù)中的一項(xiàng)功能,是用來(lái)為需要考慮不同語(yǔ)言的編程提供幫助的。舉個(gè)例子,如果你正在處理法文文本,你想用 \w+ 來(lái)匹配文字,但 \w 只匹配字符類(lèi) [A-Za-z];它并不能匹配 "é" 或 "?"。如果你的系統(tǒng)配置適當(dāng)且本地化設(shè)置為法語(yǔ),那么內(nèi)部的 C 函數(shù)將告訴程序 "é" 也應(yīng)該被認(rèn)為是一個(gè)字母。當(dāng)在編譯正則表達(dá)式時(shí)使用 LOCALE 標(biāo)志會(huì)得到用這些 C 函數(shù)來(lái)處理 \w 后的編譯對(duì)象;這會(huì)更慢,但也會(huì)象你希望的那樣可以用 \w+ 來(lái)匹配法文文本。 MMULTILINE (^ and $ haven't been explained yet; they'll be introduced in section 4.1.) (此時(shí) ^ 和 $ 不會(huì)被解釋; 它們將在 4.1 節(jié)被介紹.) Usually matches only at the beginning of the string, and $ matches only at the end of the string and immediately before the newline (if any) at the end of the string. When this flag is specified, matches at the beginning of the string and at the beginning of each line within the string, immediately following each newline. Similarly, the $ metacharacter matches either at the end of the string and at the end of each line (immediately preceding each newline). 使用 只匹配字符串的開(kāi)始,而 $ 則只匹配字符串的結(jié)尾和直接在換行前(如果有的話(huà))的字符串結(jié)尾。當(dāng)本標(biāo)志指定后, 匹配字符串的開(kāi)始和字符串中每行的開(kāi)始。同樣的, $ 元字符匹配字符串結(jié)尾和字符串中每行的結(jié)尾(直接在每個(gè)換行之前)。 SDOTALL Makes the "." special character match any character at all, including a newline; without this flag, "." will match anything except a newline. 使 "." 特殊字符完全匹配任何字符,包括換行;沒(méi)有這個(gè)標(biāo)志, "." 匹配除了換行外的任何字符。 XVERBOSE This flag allows you to write regular expressions that are more readable by granting you more flexibility in how you can format them. When this flag has been specified, whitespace within the RE string is ignored, except when the whitespace is in a character class or preceded by an unescaped backslash; this lets you organize and indent the RE more clearly. It also enables you to put comments within a RE that will be ignored by the engine; comments are marked by a "#" that's neither in a character class or preceded by an unescaped backslash. 該 標(biāo)志通過(guò)給予你更靈活的格式以便你將正則表達(dá)式寫(xiě)得更易于理解。當(dāng)該標(biāo)志被指定時(shí),在 RE 字符串中的空白符被忽略,除非該空白符在字符類(lèi)中或在反斜杠之后;這可以讓你更清晰地組織和縮進(jìn) RE。它也可以允許你將注釋寫(xiě)入 RE,這些注釋會(huì)被引擎忽略;注釋用 "#"號(hào) 來(lái)標(biāo)識(shí),不過(guò)該符號(hào)不能在字符串或反斜杠之后。 For example, here's a RE that uses re.VERBOSE; see how much easier it is to read? 舉個(gè)例子,這里有一個(gè)使用 re.VERBOSE 的 RE;看看讀它輕松了多少? Toggle line numbersToggle line numbersToggle line numbers 1 charref = re.compile(r""" 2 &[#] # Start of a numeric entity reference 3 ( 4 [0-9]+[^0-9] # Decimal form 5 | 0[0-7]+[^0-7] # Octal form 6 | x[0-9a-fA-F]+[^0-9a-fA-F] # Hexadecimal form 7 ) 8 """, re.VERBOSE) Without the verbose setting, the RE would look like this: 沒(méi)有 verbose 設(shè)置, RE 會(huì)看起來(lái)象這樣: Toggle line numbersToggle line numbersToggle line numbers 1 charref = re.compile("&#([0-9]+[^0-9]" 2 "|0[0-7]+[^0-7]" 3 "|x[0-9a-fA-F]+[^0-9a-fA-F])") In the above example, Python's automatic concatenation of string literals has been used to break up the RE into smaller pieces, but it's still more difficult to understand than the version using re.VERBOSE. 在上面的例子里,Python 的字符串自動(dòng)連接可以用來(lái)將 RE 分成更小的部分,但它比用 re.VERBOSE 標(biāo)志時(shí)更難懂。 More Pattern Power(更多模式功能)So far we've only covered a part of the features of regular expressions. In this section, we'll cover some new metacharacters, and how to use groups to retrieve portions of the text that was matched.到目前為止,我們只展示了正則表達(dá)式的一部分功能。在本節(jié),我們將展示一些新的元字符和如何使用組來(lái)檢索被匹配的文本部分。1. More Metacharacters(更多的元字符)There are some metacharacters that we haven't covered yet. Most of them will be covered in this section.還有一些我們還沒(méi)展示的元字符,其中的大部分將在本節(jié)展示。Some of the remaining metacharacters to be discussed are zero-width assertions. They don't cause the engine to advance through the string; instead, they consume no characters at all, and simply succeed or fail. For example, \b is an assertion that the current position is located at a word boundary; the position isn't changed by the \b at all. This means that zero-width assertions should never be repeated, because if they match once at a given location, they can obviously be matched an infinite number of times.剩 下來(lái)要討論的一部分元字符是零寬界定符(zero-width assertions)。它們并不會(huì)使引擎在處理字符串時(shí)更快;相反,它們根本就沒(méi)有對(duì)應(yīng)任何字符,只是簡(jiǎn)單的成功或失敗。舉個(gè)例子, \b 是一個(gè)在單詞邊界定位當(dāng)前位置的界定符(assertions),這個(gè)位置根本就不會(huì)被 \b 改變。這意味著零寬界定符(zero-width assertions)將永遠(yuǎn)不會(huì)被重復(fù),因?yàn)槿绻鼈冊(cè)诮o定位置匹配一次,那么它們很明顯可以被匹配無(wú)數(shù)次。| Alternation, or the "or" operator. If A and B are regular expressions, A|B will match any string that matches either "A" or "B". | has very low precedence in order to make it work reasonably when you're alternating multi-character strings. Crow|Servo will match either "Crow" or "Servo", not "Cro", a "w" or an "S", and "ervo". 可 選項(xiàng),或者 "or" 操作符。如果 A 和 B 是正則表達(dá)式,A|B 將匹配任何匹配了 "A" 或 "B" 的字符串。| 的優(yōu)先級(jí)非常低,是為了當(dāng)你有多字符串要選擇時(shí)能適當(dāng)?shù)剡\(yùn)行。Crow|Servo 將匹配"Crow" 或 "Servo", 而不是 "Cro", 一個(gè) "w" 或 一個(gè) "S", 和 "ervo"。 To match a literal "|", use \|, or enclose it inside a character class, as in [|]. 為了匹配字母 "|",可以用 \|,或?qū)⑵浒谧址?lèi)中,如[|]。 ^ Matches at the beginning of lines. Unless the MULTILINE flag has been set, this will only match at the beginning of the string. In MULTILINE mode, this also matches immediately after each newline within the string. 匹配行首。除非設(shè)置 MULTILINE 標(biāo)志,它只是匹配字符串的開(kāi)始。在 MULTILINE 模式里,它也可以直接匹配字符串中的每個(gè)換行。 For example, if you wish to match the word "From" only at the beginning of a line, the RE to use is ^From. 例如,如果你只希望匹配在行首單詞 "From",那么 RE 將用 ^From。 Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.search('^From', 'From Here to Eternity') 2 3 >>> print re.search('^From', 'Reciting From Memory') 4 None$ Matches at the end of a line, which is defined as either the end of the string, or any location followed by a newline character. 匹配行尾,行尾被定義為要么是字符串尾,要么是一個(gè)換行字符后面的任何位置。 Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.search('}$', '{block}') 2 3 >>> print re.search('}$', '{block} ') 4 None 5 >>> print re.search('}$', '{block}\n') 6 To match a literal "$", use \$ or enclose it inside a character class, as in [$]. 匹配一個(gè) "$",使用 \$ 或?qū)⑵浒谧址?lèi)中,如[$]。 \A Matches only at the start of the string. When not in MULTILINE mode, \A and are effectively the same. In MULTILINE mode, however, they're different; \A still matches only at the beginning of the string, but may match at any location inside the string that follows a newline character. 只匹配字符串首。當(dāng)不在 MULTILINE 模式,\A 和 實(shí)際上是一樣的。然而,在 MULTILINE 模式里它們是不同的;\A 只是匹配字符串首,而 還可以匹配在換行符之后字符串的任何位置。 \Z Matches only at the end of the string. 只匹配字符串尾。 \b Word boundary. This is a zero-width assertion that matches only at the beginning or end of a word. A word is defined as a sequence of alphanumeric characters, so the end of a word is indicated by whitespace or a non-alphanumeric character. 單詞邊界。這是個(gè)零寬界定符(zero-width assertions)只用以匹配單詞的詞首和詞尾。單詞被定義為一個(gè)字母數(shù)字序列,因此詞尾就是用空白符或非字母數(shù)字符來(lái)標(biāo)示的。 The following example matches "class" only when it's a complete word; it won't match when it's contained inside another word. 下面的例子只匹配 "class" 整個(gè)單詞;而當(dāng)它被包含在其他單詞中時(shí)不匹配。 Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'\bclass\b') 2 >>> print p.search('no class at all') 3 4 >>> print p.search('the declassified algorithm') 5 None 6 >>> print p.search('one subclass is') 7 None There are two subtleties you should remember when using this special sequence. First, this is the worst collision between Python's string literals and regular expression sequences. In Python's string literals, "\b" is the backspace character, ASCII value 8. If you're not using raw strings, then Python will convert the "\b" to a backspace, and your RE won't match as you expect it to. The following example looks the same as our previous RE, but omits the "r" in front of the RE string. 當(dāng) 用這個(gè)特殊序列時(shí)你應(yīng)該記住這里有兩個(gè)微妙之處。第一個(gè)是 Python 字符串和正則表達(dá)式之間最糟的沖突。在 Python 字符串里,"\b" 是反斜杠字符,ASCII值是8。如果你沒(méi)有使用 raw 字符串時(shí),那么 Python 將會(huì)把 "\b" 轉(zhuǎn)換成一個(gè)回退符,你的 RE 將無(wú)法象你希望的那樣匹配它了。下面的例子看起來(lái)和我們前面的 RE 一樣,但在 RE 字符串前少了一個(gè) "r" 。 Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('\bclass\b') 2 >>> print p.search('no class at all') 3 None 4 >>> print p.search('\b' + 'class' + '\b') 5 Second, inside a character class, where there's no use for this assertion, \b represents the backspace character, for compatibility with Python's string literals. 第二個(gè)在字符類(lèi)中,這個(gè)限定符(assertion)不起作用,\b 表示回退符,以便與 Python 字符串兼容。 \B Another zero-width assertion, this is the opposite of \b, only matching when the current position is not at a word boundary. 另一個(gè)零寬界定符(zero-width assertions),它正好同 \b 相反,只在當(dāng)前位置不在單詞邊界時(shí)匹配。 2. Grouping(分組)Frequently you need to obtain more information than just whether the RE matched or not. Regular expressions are often used to dissect strings by writing a RE divided into several subgroups which match different components of interest. For example, an RFC-822 header line is divided into a header name and a value, separated by a ":". This can be handled by writing a regular expression which matches an entire header line, and has one group which matches the header name, and another group which matches the header's value.你經(jīng)常 需要得到比 RE 是否匹配還要多的信息。正則表達(dá)式常常用來(lái)分析字符串,編寫(xiě)一個(gè) RE 匹配感興趣的部分并將其分成幾個(gè)小組。舉個(gè)例子,一個(gè) RFC-822 的頭部用 ":" 隔成一個(gè)頭部名和一個(gè)值,這就可以通過(guò)編寫(xiě)一個(gè)正則表達(dá)式匹配整個(gè)頭部,用一組匹配頭部名,另一組匹配頭部值的方式來(lái)處理。Groups are marked by the "(", ")" metacharacters. "(" and ")" have much the same meaning as they do in mathematical expressions; they group together the expressions contained inside them. For example, you can repeat the contents of a group with a repeating qualifier, such as *, +, ?, or {m,n}. For example, (ab)* will match zero or more repetitions of "ab".組是通過(guò) "(" 和 ")" 元字符來(lái)標(biāo)識(shí)的。 "(" 和 ")" 有很多在數(shù)學(xué)表達(dá)式中相同的意思;它們一起把在它們里面的表達(dá)式組成一組。舉個(gè)例子,你可以用重復(fù)限制符,象 *, +, ?, 和 {m,n},來(lái)重復(fù)組里的內(nèi)容,比如說(shuō)(ab)* 將匹配零或更多個(gè)重復(fù)的 "ab"。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('(ab)*') 2 >>> print p.match('ababababab').span() 3 (0, 10)Groups indicated with "(", ")" also capture the starting and ending index of the text that they match; this can be retrieved by passing an argument to group(), start(), end(), and span(). Groups are numbered starting with 0. Group 0 is always present; it's the whole RE, so MatchObject methods all have group 0 as their default argument. Later we'll see how to express groups that don't capture the span of text that they match.組用 "(" 和 ")" 來(lái)指定,并且得到它們匹配文本的開(kāi)始和結(jié)尾索引;這就可以通過(guò)一個(gè)參數(shù)用 group()、start()、end() 和 span() 來(lái)進(jìn)行檢索。組是從 0 開(kāi)始計(jì)數(shù)的。組 0 總是存在;它就是整個(gè) RE,所以 MatchObject 的方法都把組 0 作為它們?nèi)笔〉膮?shù)。稍后我們將看到怎樣表達(dá)不能得到它們所匹配文本的 span。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('(a)b') 2 >>> m = p.match('ab') 3 >>> m.group() 4 'ab' 5 >>> m.group(0) 6 'ab'Subgroups are numbered from left to right, from 1 upward. Groups can be nested; to determine the number, just count the opening parenthesis characters, going from left to right.小組是從左向右計(jì)數(shù)的,從1開(kāi)始。組可以被嵌套。計(jì)數(shù)的數(shù)值可以能過(guò)從左到右計(jì)算打開(kāi)的括號(hào)數(shù)來(lái)確定。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('(a(b)c)d') 2 >>> m = p.match('abcd') 3 >>> m.group(0) 4 'abcd' 5 >>> m.group(1) 6 'abc' 7 >>> m.group(2) 8 'b'group() can be passed multiple group numbers at a time, in which case it will return a tuple containing the corresponding values for those groups.group() 可以一次輸入多個(gè)組號(hào),在這種情況下它將返回一個(gè)包含那些組所對(duì)應(yīng)值的元組。Toggle line numbersToggle line numbersToggle line numbers 1 >>> m.group(2,1,2) 2 ('b', 'abc', 'b')The groups() method returns a tuple containing the strings for all the subgroups, from 1 up to however many there are.The groups() 方法返回一個(gè)包含所有小組字符串的元組,從 1 到 所含的小組號(hào)。Toggle line numbersToggle line numbersToggle line numbers 1 >>> m.groups() 2 ('abc', 'b')Backreferences in a pattern allow you to specify that the contents of an earlier capturing group must also be found at the current location in the string. For example, \1 will succeed if the exact contents of group 1 can be found at the current position, and fails otherwise. Remember that Python's string literals also use a backslash followed by numbers to allow including arbitrary characters in a string, so be sure to use a raw string when incorporating backreferences in a RE.模 式中的逆向引用允許你指定先前捕獲組的內(nèi)容,該組也必須在字符串當(dāng)前位置被找到。舉個(gè)例子,如果組 1 的內(nèi)容能夠在當(dāng)前位置找到的話(huà),\1 就成功否則失敗。記住 Python 字符串也是用反斜杠加數(shù)據(jù)來(lái)允許字符串中包含任意字符的,所以當(dāng)在 RE 中使用逆向引用時(shí)確保使用 raw 字符串。For example, the following RE detects doubled words in a string.例如,下面的 RE 在一個(gè)字符串中找到成雙的詞。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'(\b\w+)\s+\1') 2 >>> p.search('Paris in the the spring').group() 3 'the the'Backreferences like this aren't often useful for just searching through a string -- there are few text formats which repeat data in this way -- but you'll soon find out that they're very useful when performing string substitutions.象這樣只是搜索一個(gè)字符串的逆向引用并不常見(jiàn) -- 用這種方式重復(fù)數(shù)據(jù)的文本格式并不多見(jiàn) -- 但你不久就可以發(fā)現(xiàn)它們用在字符串替換上非常有用。3. Non-capturing and Named Groups(無(wú)捕獲組和命名組)Elaborate REs may use many groups, both to capture substrings of interest, and to group and structure the RE itself. In complex REs, it becomes difficult to keep track of the group numbers. There are two features which help with this problem. Both of them use a common syntax for regular expression extensions, so we'll look at that first.精心設(shè)計(jì)的 REs 也許會(huì)用很多組,既可以捕獲感興趣的子串,又可以分組和結(jié)構(gòu)化 RE 本身。在復(fù)雜的 REs 里,追蹤組號(hào)變得困難。有兩個(gè)功能可以對(duì)這個(gè)問(wèn)題有所幫助。它們也都使用正則表達(dá)式擴(kuò)展的通用語(yǔ)法,因此我們來(lái)看看第一個(gè)。Perl 5 added several additional features to standard regular expressions, and the Python re module supports most of them. It would have been difficult to choose new single-keystroke metacharacters or new special sequences beginning with "\" to represent the new features without making Perl's regular expressions confusingly different from standard REs. If you chose "&" as a new metacharacter, for example, old expressions would be assuming that "&" was a regular character and wouldn't have escaped it by writing \& or [&].Perl 5 對(duì)標(biāo)準(zhǔn)正則表達(dá)式增加了幾個(gè)附加功能,Python 的 re 模塊也支持其中的大部分。選擇一個(gè)新的單按鍵元字符或一個(gè)以 "\" 開(kāi)始的特殊序列來(lái)表示新的功能,而又不會(huì)使 Perl 正則表達(dá)式與標(biāo)準(zhǔn)正則表達(dá)式產(chǎn)生混亂是有難度的。如果你選擇 "&" 做為新的元字符,舉個(gè)例子,老的表達(dá)式認(rèn)為 "&" 是一個(gè)正常的字符,而不會(huì)在使用 \& 或 [&] 時(shí)也不會(huì)轉(zhuǎn)義。The solution chosen by the Perl developers was to use (?...) as the extension syntax. "?" immediately after a parenthesis was a syntax error because the "?" would have nothing to repeat, so this didn't introduce any compatibility problems. The characters immediately after the "?" indicate what extension is being used, so (?=foo) is one thing (a positive lookahead assertion) and (?:foo) is something else (a non-capturing group containing the subexpression foo).Perl 開(kāi)發(fā)人員的解決方法是使用 (?...) 來(lái)做為擴(kuò)展語(yǔ)法。"?" 在括號(hào)后面會(huì)直接導(dǎo)致一個(gè)語(yǔ)法錯(cuò)誤,因?yàn)?"?" 沒(méi)有任何字符可以重復(fù),因此它不會(huì)產(chǎn)生任何兼容問(wèn)題。緊隨 "?" 之后的字符指出擴(kuò)展的用途,因此 (?=foo)Python adds an extension syntax to Perl's extension syntax. If the first character after the question mark is a "P", you know that it's an extension that's specific to Python. Currently there are two such extensions: (?P...) defines a named group, and (?P=name) is a backreference to a named group. If future versions of Perl 5 add similar features using a different syntax, the re module will be changed to support the new syntax, while preserving the Python-specific syntax for compatibility's sake.Python 新增了一個(gè)擴(kuò)展語(yǔ)法到 Perl 擴(kuò)展語(yǔ)法中。如果在問(wèn)號(hào)后的第一個(gè)字符是 "P",你就可以知道它是針對(duì) Python 的擴(kuò)展。目前有兩個(gè)這樣的擴(kuò)展: (?P...) 定義一個(gè)命名組,(?P=name) 則是對(duì)命名組的逆向引用。如果 Perl 5 的未來(lái)版本使用不同的語(yǔ)法增加了相同的功能,那么 re 模塊也將改變以支持新的語(yǔ)法,這是為了兼容性的目的而保持的 Python 專(zhuān)用語(yǔ)法。Now that we've looked at the general extension syntax, we can return to the features that simplify working with groups in complex REs. Since groups are numbered from left to right and a complex expression may use many groups, it can become difficult to keep track of the correct numbering, and modifying such a complex RE is annoying. Insert a new group near the beginning, and you change the numbers of everything that follows it.現(xiàn)在我們看一下普通的擴(kuò)展語(yǔ)法,我們回過(guò) 頭來(lái)簡(jiǎn)化在復(fù)雜 REs 中使用組運(yùn)行的特性。因?yàn)榻M是從左到右編號(hào)的,而且一個(gè)復(fù)雜的表達(dá)式也許會(huì)使用許多組,它可以使跟蹤當(dāng)前組號(hào)變得困難,而修改如此復(fù)雜的 RE 是十分麻煩的。在開(kāi)始時(shí)插入一個(gè)新組,你可以改變它之后的每個(gè)組號(hào)。First, sometimes you'll want to use a group to collect a part of a regular expression, but aren't interested in retrieving the group's contents. You can make this fact explicit by using a non-capturing group: (?:...), where you can put any other regular expression inside the parentheses.首先,有時(shí)你想用一個(gè)組去收集正則表達(dá)式的一部分,但又對(duì)組的內(nèi)容不感興趣。你可以用一個(gè)無(wú)捕獲組: (?:...) 來(lái)實(shí)現(xiàn)這項(xiàng)功能,這樣你可以在括號(hào)中發(fā)送任何其他正則表達(dá)式。Toggle line numbersToggle line numbersToggle line numbers 1 >>> m = re.match("([abc])+", "abc") 2 >>> m.groups() 3 ('c',) 4 >>> m = re.match("(?:[abc])+", "abc") 5 >>> m.groups() 6 ()Except for the fact that you can't retrieve the contents of what the group matched, a non-capturing group behaves exactly the same as a capturing group; you can put anything inside it, repeat it with a repetition metacharacter such as "*", and nest it within other groups (capturing or non-capturing). (?:...) is particularly useful when modifying an existing group, since you can add new groups without changing how all the other groups are numbered. It should be mentioned that there's no performance difference in searching between capturing and non-capturing groups; neither form is any faster than the other.除 了捕獲匹配組的內(nèi)容之外,無(wú)捕獲組與捕獲組表現(xiàn)完全一樣;你可以在其中放置任何字符,可以用重復(fù)元字符如 "*" 來(lái)重復(fù)它,可以在其他組(無(wú)捕獲組與捕獲組)中嵌套它。(?:...) 對(duì)于修改已有組尤其有用,因?yàn)槟憧梢圆挥酶淖兯衅渌M號(hào)的情況下添加一個(gè)新組。捕獲組和無(wú)捕獲組在搜索效率方面也沒(méi)什么不同,沒(méi)有哪一個(gè)比另一個(gè)更快。The second, and more significant, feature is named groups; instead of referring to them by numbers, groups can be referenced by a name.其次,更重要和強(qiáng)大的是命名組;與用數(shù)字指定組不同的是,它可以用名字來(lái)指定。The syntax for a named group is one of the Python-specific extensions: (?P...). name is, obviously, the name of the group. Except for associating a name with a group, named groups also behave identically to capturing groups. The MatchObject methods that deal with capturing groups all accept either integers, to refer to groups by number, or a string containing the group name. Named groups are still given numbers, so you can retrieve information about a group in two ways:命令組的語(yǔ)法是 Python 專(zhuān)用擴(kuò)展之一: (?P...)。名字很明顯是組的名字。除了該組有個(gè)名字之外,命名組也同捕獲組是相同的。MatchObject 的方法處理捕獲組時(shí)接受的要么是表示組號(hào)的整數(shù),要么是包含組名的字符串。命名組也可以是數(shù)字,所以你可以通過(guò)兩種方式來(lái)得到一個(gè)組的信息:Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'(?P\b\w+\b)') 2 >>> m = p.search( '(((( Lots of punctuation )))' ) 3 >>> m.group('word') 4 'Lots' 5 >>> m.group(1) 6 'Lots'Named groups are handy because they let you use easily-remembered names, instead of having to remember numbers. Here's an example RE from the imaplib module:命名組是便于使用的,因?yàn)樗梢宰屇闶褂萌菀子涀〉拿謥?lái)代替不得不記住的數(shù)字。這里有一個(gè)來(lái)自 imaplib 模塊的 RE 示例:Toggle line numbersToggle line numbersToggle line numbers 1 InternalDate = re.compile(r'INTERNALDATE "' 2 r'(?P[ 123][0-9])-(?P[A-Z][a-z][a-z])-' 3 r'(?P[0-9][0-9][0-9][0-9])' 4 r' (?P[0-9][0-9]):(?P[0-9][0-9]):(?P[0-9][0-9])' 5 r' (?P[-+])(?P[0-9][0-9])(?P[0-9][0-9])' 6 r'"')It's obviously much easier to retrieve m.group('zonem'), instead of having to remember to retrieve group 9.很明顯,得到 m.group('zonem') 要比記住得到組 9 要容易得多。Since the syntax for backreferences, in an expression like (...)\1, refers to the number of the group there's naturally a variant that uses the group name instead of the number. This is also a Python extension: (?P=name) indicates that the contents of the group called name should again be found at the current point. The regular expression for finding doubled words, (\b\w+)\s+\1 can also be written as (?P\b\w+)\s+(?P=word):因 為逆向引用的語(yǔ)法,象 (...)\1 這樣的表達(dá)式所表示的是組號(hào),這時(shí)用組名代替組號(hào)自然會(huì)有差別。還有一個(gè) Python 擴(kuò)展:(?P=name) ,它可以使叫 name 的組內(nèi)容再次在當(dāng)前位置發(fā)現(xiàn)。正則表達(dá)式為了找到重復(fù)的單詞,(\b\w+)\s+\1 也可以被寫(xiě)成 (?P\b\w+)\s+(?P=word):Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'(?P\b\w+)\s+(?P=word)') 2 >>> p.search('Paris in the the spring').group() 3 'the the'4. Lookahead Assertions(前向界定符)Another zero-width assertion is the lookahead assertion. Lookahead assertions are available in both positive and negative form, and look like this:另一個(gè)零寬界定符(zero-width assertion)是前向界定符。前向界定符包括前向肯定界定符和后向肯定界定符,所下所示:(?=...) Positive lookahead assertion. This succeeds if the contained regular expression, represented here by ..., successfully matches at the current location, and fails otherwise. But, once the contained expression has been tried, the matching engine doesn't advance at all; the rest of the pattern is tried right where the assertion started. 前向肯定界定符。如果所含正則表達(dá)式,以 ... 表示,在當(dāng)前位置成功匹配時(shí)成功,否則失敗。但一旦所含表達(dá)式已經(jīng)嘗試,匹配引擎根本沒(méi)有提高;模式的剩余部分還要嘗試界定符的右邊。 (?!...) Negative lookahead assertion. This is the opposite of the positive assertion; it succeeds if the contained expression doesn't match at the current position in the string. 前向否定界定符。與肯定界定符相反;當(dāng)所含表達(dá)式不能在字符串當(dāng)前位置匹配時(shí)成功 An example will help make this concrete by demonstrating a case where a lookahead is useful. Consider a simple pattern to match a filename and split it apart into a base name and an extension, separated by a ".". For example, in "news.rc", "news" is the base name, and "rc" is the filename's extension.通過(guò)示范在哪前向可以成功有助于具體實(shí)現(xiàn)。考慮一個(gè)簡(jiǎn)單的模式用于匹配一個(gè)文件名,并將其通過(guò) "." 分成基本名和擴(kuò)展名兩部分。如在 "news.rc" 中,"news" 是基本名,"rc" 是文件的擴(kuò)展名。The pattern to match this is quite simple:匹配模式非常簡(jiǎn)單:.*[.].*$Notice that the "." needs to be treated specially because it's a metacharacter; I've put it inside a character class. Also notice the trailing $; this is added to ensure that all the rest of the string must be included in the extension. This regular expression matches "foo.bar" and "autoexec.bat" and "sendmail.cf" and "printers.conf".注 意 "." 需要特殊對(duì)待,因?yàn)樗且粋€(gè)元字符;我把它放在一個(gè)字符類(lèi)中。另外注意后面的 $; 添加這個(gè)是為了確保字符串所有的剩余部分必須被包含在擴(kuò)展名中。這個(gè)正則表達(dá)式匹配 "foo.bar"、"autoexec.bat"、 "sendmail.cf" 和 "printers.conf"。Now, consider complicating the problem a bit; what if you want to match filenames where the extension is not "bat"? Some incorrect attempts:現(xiàn)在,考慮把問(wèn)題變得復(fù)雜點(diǎn);如果你想匹配的擴(kuò)展名不是 "bat" 的文件名?一些不正確的嘗試:.*[.][^b].*$The first attempt above tries to exclude "bat" by requiring that the first character of the extension is not a "b". This is wrong, because the pattern also doesn't match "foo.bar".上面的第一次去除 "bat" 的嘗試是要求擴(kuò)展名的第一個(gè)字符不是 "b"。這是錯(cuò)誤的,因?yàn)樵撃J揭膊荒芷ヅ?"foo.bar"。.*[.]([^b]..|.[^a].|..[^t])$The expression gets messier when you try to patch up the first solution by requiring one of the following cases to match: the first character of the extension isn't "b"; the second character isn't "a"; or the third character isn't "t". This accepts "foo.bar" and rejects "autoexec.bat", but it requires a three-letter extension and won't accept a filename with a two-letter extension such as "sendmail.cf". We'll complicate the pattern again in an effort to fix it.當(dāng) 你試著修補(bǔ)第一個(gè)解決方法而要求匹配下列情況之一時(shí)表達(dá)式更亂了:擴(kuò)展名的第一個(gè)字符不是 "b"; 第二個(gè)字符不是 "a";或第三個(gè)字符不是 "t"。這樣可以接受 "foo.bar" 而拒絕 "autoexec.bat",但這要求只能是三個(gè)字符的擴(kuò)展名而不接受兩個(gè)字符的擴(kuò)展名如 "sendmail.cf"。我們將在努力修補(bǔ)它時(shí)再次把該模式變得復(fù)雜。.*[.]([^b].?.?|.[^a]?.?|..?[^t]?)$In the third attempt, the second and third letters are all made optional in order to allow matching extensions shorter than three characters, such as "sendmail.cf".在第三次嘗試中,第二和第三個(gè)字母都變成可選,為的是允許匹配比三個(gè)字符更短的擴(kuò)展名,如 "sendmail.cf"。The pattern's getting really complicated now, which makes it hard to read and understand. Worse, if the problem changes and you want to exclude both "bat" and "exe" as extensions, the pattern would get even more complicated and confusing.該模式現(xiàn)在變得非常復(fù)雜,這使它很難讀懂。更糟的是,如果問(wèn)題變化了,你想擴(kuò)展名不是 "bat" 和 "exe",該模式甚至?xí)兊酶鼜?fù)雜和混亂。A negative lookahead cuts through all this:前向否定把所有這些裁剪成:.*[.](?!bat$).*$The lookahead means: if the expression bat doesn't match at this point, try the rest of the pattern; if bat$ does match, the whole pattern will fail. The trailing $ is required to ensure that something like "sample.batch", where the extension only starts with "bat", will be allowed.前向的意思:如果表達(dá)式 bat 在這里沒(méi)有匹配,嘗試模式的其余部分;如果 bat$ 匹配,整個(gè)模式將失敗。后面的 $ 被要求是為了確保象 "sample.batch" 這樣擴(kuò)展名以 "bat" 開(kāi)頭的會(huì)被允許。Excluding another filename extension is now easy; simply add it as an alternative inside the assertion. The following pattern excludes filenames that end in either "bat" or "exe":將另一個(gè)文件擴(kuò)展名排除在外現(xiàn)在也容易;簡(jiǎn)單地將其做為可選項(xiàng)放在界定符中。下面的這個(gè)模式將以 "bat" 或 "exe" 結(jié)尾的文件名排除在外。.*[.](?!bat$|exe$).*$Modifying Strings(修改字符串)Up to this point, we've simply performed searches against a static string. Regular expressions are also commonly used to modify a string in various ways, using the following RegexObject methods:到目前為止,我們簡(jiǎn)單地搜索了一個(gè)靜態(tài)字符串。正則表達(dá)式通常也用不同的方式,通過(guò)下面的 RegexObject 方法,來(lái)修改字符串。Method/Attribute(方法/屬性)Purpose(作用)split()Split the string into a list, splitting it wherever the RE matches將字符串在 RE 匹配的地方分片并生成一個(gè)列表,sub()Find all substrings where the RE matches, and replace them with a different string找到 RE 匹配的所有子串,并將其用一個(gè)不同的字符串替換subn()Does the same thing as sub(), but returns the new string and the number of replacements與 sub() 相同,但返回新的字符串和替換次數(shù)1. Splitting Strings(將字符串分片)The split() method of a RegexObject splits a string apart wherever the RE matches, returning a list of the pieces. It's similar to the split() method of strings but provides much more generality in the delimiters that you can split by; split() only supports splitting by whitespace or by a fixed string. As you'd expect, there's a module-level re.split() function, too.RegexObject 的 split() 方法在 RE 匹配的地方將字符串分片,將返回列表。它同字符串的 split() 方法相似但提供更多的定界符;split()只支持空白符和固定字符串。就象你預(yù)料的那樣,也有一個(gè)模塊級(jí)的 re.split() 函數(shù)。split(string [, maxsplit = 0]) Split string by the matches of the regular expression. If capturing parentheses are used in the RE, then their contents will also be returned as part of the resulting list. If maxsplit is nonzero, at most maxsplit splits are performed. 通過(guò)正則表達(dá)式將字符串分片。如果捕獲括號(hào)在 RE 中使用,那么它們的內(nèi)容也會(huì)作為結(jié)果列表的一部分返回。如果 maxsplit 非零,那么最多只能分出 maxsplit 個(gè)分片。 You can limit the number of splits made, by passing a value for maxsplit. When maxsplit is nonzero, at most maxsplit splits will be made, and the remainder of the string is returned as the final element of the list. In the following example, the delimiter is any sequence of non-alphanumeric characters.你可以通過(guò)設(shè)置 maxsplit 值來(lái)限制分片數(shù)。當(dāng) maxsplit 非零時(shí),最多只能有 maxsplit 個(gè)分片,字符串的其余部分被做為列表的最后部分返回。在下面的例子中,定界符可以是非數(shù)字字母字符的任意序列。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'\W+') 2 >>> p.split('This is a test, short and sweet, of split().') 3 ['This', 'is', 'a', 'test', 'short', 'and', 'sweet', 'of', 'split', ''] 4 >>> p.split('This is a test, short and sweet, of split().', 3) 5 ['This', 'is', 'a', 'test, short and sweet, of split().']Sometimes you're not only interested in what the text between delimiters is, but also need to know what the delimiter was. If capturing parentheses are used in the RE, then their values are also returned as part of the list. Compare the following calls:有時(shí),你不僅對(duì)定界符之間的文本感興趣,也需要知道定界符是什么。如果捕獲括號(hào)在 RE 中使用,那么它們的值也會(huì)當(dāng)作列表的一部分返回。比較下面的調(diào)用:Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile(r'\W+') 2 >>> p2 = re.compile(r'(\W+)') 3 >>> p.split('This... is a test.') 4 ['This', 'is', 'a', 'test', ''] 5 >>> p2.split('This... is a test.') 6 ['This', '... ', 'is', ' ', 'a', ' ', 'test', '.', '']The module-level function re.split() adds the RE to be used as the first argument, but is otherwise the same.模塊級(jí)函數(shù) re.split() 將 RE 作為第一個(gè)參數(shù),其他一樣。Toggle line numbersToggle line numbersToggle line numbers 1 >>> re.split('[\W]+', 'Words, words, words.') 2 ['Words', 'words', 'words', ''] 3 >>> re.split('([\W]+)', 'Words, words, words.') 4 ['Words', ', ', 'words', ', ', 'words', '.', ''] 5 >>> re.split('[\W]+', 'Words, words, words.', 1) 6 ['Words', 'words, words.']2. Search and Replace(搜索和替換)Another common task is to find all the matches for a pattern, and replace them with a different string. The sub() method takes a replacement value, which can be either a string or a function, and the string to be processed.其他常見(jiàn)的用途就是找到所有模式匹配的字符串并用不同的字符串來(lái)替換它們。sub() 方法提供一個(gè)替換值,可以是字符串或一個(gè)函數(shù),和一個(gè)要被處理的字符串。sub(replacement, string[, count = 0]) Returns the string obtained by replacing the leftmost non-overlapping occurrences of the RE in string by the replacement replacement. If the pattern isn't found, string is returned unchanged. 返回的字符串是在字符串中用 RE 最左邊不重復(fù)的匹配來(lái)替換。如果模式?jīng)]有發(fā)現(xiàn),字符將被沒(méi)有改變地返回。 The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. The default value of 0 means to replace all occurrences. 可選參數(shù) count 是模式匹配后替換的最大次數(shù);count 必須是非負(fù)整數(shù)。缺省值是 0 表示替換所有的匹配。 Here's a simple example of using the sub() method. It replaces colour names with the word "colour":這里有個(gè)使用 sub() 方法的簡(jiǎn)單例子。它用單詞 "colour" 替換顏色名。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile( '(blue|white|red)') 2 >>> p.sub( 'colour', 'blue socks and red shoes') 3 'colour socks and colour shoes' 4 >>> p.sub( 'colour', 'blue socks and red shoes', count=1) 5 'colour socks and red shoes'The subn() method does the same work, but returns a 2-tuple containing the new string value and the number of replacements that were performed:subn() 方法作用一樣,但返回的是包含新字符串和替換執(zhí)行次數(shù)的兩元組。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile( '(blue|white|red)') 2 >>> p.subn( 'colour', 'blue socks and red shoes') 3 ('colour socks and colour shoes', 2) 4 >>> p.subn( 'colour', 'no colours at all') 5 ('no colours at all', 0)Empty matches are replaced only when they're not adjacent to a previous match.空匹配只有在它們沒(méi)有緊挨著前一個(gè)匹配時(shí)才會(huì)被替換掉。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('x*') 2 >>> p.sub('-', 'abxd') 3 '-a-b-d-'If replacement is a string, any backslash escapes in it are processed. That is, "\n" is converted to a single newline character, "\r" is converted to a carriage return, and so forth. Unknown escapes such as "\j" are left alone. Backreferences, such as "\6", are replaced with the substring matched by the corresponding group in the RE. This lets you incorporate portions of the original text in the resulting replacement string.如果替 換的是一個(gè)字符串,任何在其中的反斜杠都會(huì)被處理。"\n" 將會(huì)被轉(zhuǎn)換成一個(gè)換行符,"\r"轉(zhuǎn)換成回車(chē)等等。未知的轉(zhuǎn)義如 "\j" 是 left alone。逆向引用,如 "\6",被 RE 中相應(yīng)的組匹配而被子串替換。這使你可以在替換后的字符串中插入原始文本的一部分。This example matches the word "section" followed by a string enclosed in "{", "}", and changes "section" to "subsection":這個(gè)例子匹配被 "{" 和 "}" 括起來(lái)的單詞 "section",并將 "section" 替換成 "subsection"。Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('section{ ( [^}]* ) }', re.VERBOSE) 2 >>> p.sub(r'subsection{\1}','section{First} section{second}') 3 'subsection{First} subsection{second}'There's also a syntax for referring to named groups as defined by the (?P...) syntax. "\g" will use the substring matched by the group named "name", and "\g" uses the corresponding group number. "\g<2>" is therefore equivalent to "\2", but isn't ambiguous in a replacement string such as "\g<2>0". ("\20" would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character "0".) The following substitutions are all equivalent, but use all three variations of the replacement string.還 可以指定用 (?P...) 語(yǔ)法定義的命名組。"\g" 將通過(guò)組名 "name" 用子串來(lái)匹配,并且 "\g" 使用相應(yīng)的組號(hào)。所以 "\g<2>" 等于 "\2",但能在替換字符串里含義不清,如 "\g<2>0"。("\20" 被解釋成對(duì)組 20 的引用,而不是對(duì)后面跟著一個(gè)字母 "0" 的組 2 的引用。)Toggle line numbersToggle line numbersToggle line numbers 1 >>> p = re.compile('section{ (?P [^}]* ) }', re.VERBOSE) 2 >>> p.sub(r'subsection{\1}','section{First}') 3 'subsection{First}' 4 >>> p.sub(r'subsection{\g<1>}','section{First}') 5 'subsection{First}' 6 >>> p.sub(r'subsection{\g}','section{First}') 7 'subsection{First}'replacement can also be a function, which gives you even more control. If replacement is a function, the function is called for every non-overlapping occurrence of pattern. On each call, the function is passed a MatchObject argument for the match and can use this information to compute the desired replacement string and return it.替換也可以是一個(gè)甚至給你更多控制的函數(shù)。如果替換是個(gè)函數(shù),該函數(shù)將會(huì)被模式中每一個(gè)不重復(fù)的匹配所調(diào)用。在每個(gè)調(diào)用時(shí),函數(shù)被作為 MatchObject 的匹配函屬,并可以使用這個(gè)信息去計(jì)算預(yù)期的字符串并返回它。In the following example, the replacement function translates decimals into hexadecimal:在下面的例子里,替換函數(shù)將十進(jìn)制翻譯成十六進(jìn)制:Toggle line numbersToggle line numbersToggle line numbers 1 >>> def hexrepl( match ): 2 ... "Return the hex string for a decimal number" 3 ... value = int( match.group() ) 4 ... return hex(value) 5 ... 6 >>> p = re.compile(r'\d+') 7 >>> p.sub(hexrepl, 'Call 65490 for printing, 49152 for user code.') 8 'Call 0xffd2 for printing, 0xc000 for user code.'When using the module-level re.sub() function, the pattern is passed as the first argument. The pattern may be a string or a RegexObject; if you need to specify regular expression flags, you must either use a RegexObject as the first parameter, or use embedded modifiers in the pattern, e.g. sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'.當(dāng)使用模塊級(jí)的 re.sub() 函數(shù)時(shí),模式作為第一個(gè)參數(shù)。模式也許是一個(gè)字符串或一個(gè) RegexObject;如果你需要指定正則表達(dá)式標(biāo)志,你必須要么使用 RegexObject 做第一個(gè)參數(shù),或用使用模式內(nèi)嵌修正器,如 sub("(?i)b+", "x", "bbbb BBBB") returns 'x x'。Common Problems(常見(jiàn)問(wèn)題)Regular expressions are a powerful tool for some applications, but in some ways their behaviour isn't intuitive and at times they don't behave the way you may expect them to. This section will point out some of the most common pitfalls.正則表達(dá)式對(duì)一些應(yīng)用程序來(lái)說(shuō)是一個(gè)強(qiáng)大的工具,但在有些時(shí)候它并不直觀(guān)而且有時(shí)它們不按你期望的運(yùn)行。本節(jié)將指出一些最容易犯的常見(jiàn)錯(cuò)誤。1. Use String Methods(使用字符串方式)Sometimes using the re module is a mistake. If you're matching a fixed string, or a single character class, and you're not using any re features such as the IGNORECASE flag, then the full power of regular expressions may not be required. Strings have several methods for performing operations with fixed strings and they're usually much faster, because the implementation is a single small C loop that's been optimized for the purpose, instead of the large, more generalized regular expression engine.有時(shí)使用 re 模塊是個(gè)錯(cuò)誤。如果你匹配一個(gè)固定的字符串或單個(gè)的字符類(lèi),并且你沒(méi)有使用 re 的任何象 IGNORECASE 標(biāo)志的功能,那么就沒(méi)有必要使用正則表達(dá)式了。字符串有一些方法是對(duì)固定字符串進(jìn)行操作的,它們通常快很多,因?yàn)槎际且粋€(gè)個(gè)經(jīng)過(guò)優(yōu)化的C 小循環(huán),用以代替大的、更具通用性的正則表達(dá)式引擎。One example might be replacing a single fixed string with another one; for example, you might replace "word" with "deed". re.sub() seems like the function to use for this, but consider the replace() method. Note that replace() will also replace "word" inside words, turning "swordfish" into "sdeedfish", but the na?ve RE word would have done that, too. (To avoid performing the substitution on parts of words, the pattern would have to be \bword\b, in order to require that "word" have a word boundary on either side. This takes the job beyond replace's abilities.)舉個(gè)用一個(gè)固定字符串替 換另一個(gè)的例子;如,你可以把 "deed" 替換成 "word"。re.sub() seems like the function to use for this, but consider the replace() method. 注意 replace() 也可以在單詞里面進(jìn)行替換,可以把 "swordfish" 變成 "sdeedfish",不過(guò) RE 也是可以做到的。(為了避免替換單詞的一部分,模式將寫(xiě)成 \bword\b,這是為了要求 "word" 兩邊有一個(gè)單詞邊界。這是個(gè)超出替換能力的工作)。Another common task is deleting every occurrence of a single character from a string or replacing it with another single character. You might do this with something like re.sub('\n', ' ', S), but translate() is capable of doing both tasks and will be faster that any regular expression operation can be.另一個(gè)常見(jiàn)任務(wù)是從一個(gè)字符串中刪除單個(gè)字符或用另一個(gè)字符來(lái)替代它。你也許可以用象 re.sub('\n',' ',S) 這樣來(lái)實(shí)現(xiàn),但 translate() 能夠?qū)崿F(xiàn)這兩個(gè)任務(wù),而且比任何正則表達(dá)式操作起來(lái)更快。In short, before turning to the re module, consider whether your problem can be solved with a faster and simpler string method.總之,在使用 re 模塊之前,先考慮一下你的問(wèn)題是否可以用更快、更簡(jiǎn)單的字符串方法來(lái)解決。2. match() versus search()(match() vs search())The match() function only checks if the RE matches at the beginning of the string while search() will scan forward through the string for a match. It's important to keep this distinction in mind. Remember, match() will only report a successful match which will start at 0; if the match wouldn't start at zero, match() will not report it.match() 函數(shù)只檢查 RE 是否在字符串開(kāi)始處匹配,而 search() 則是掃描整個(gè)字符串。記住這一區(qū)別是重要的。記住,match() 只報(bào)告一次成功的匹配,它將從 0 處開(kāi)始;如果匹配不是從 0 開(kāi)始的,match() 將不會(huì)報(bào)告它。Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.match('super', 'superstition').span() 2 (0, 5) 3 >>> print re.match('super', 'insuperable') 4 NoneOn the other hand, search() will scan forward through the string, reporting the first match it finds.另一方面,search() 將掃描整個(gè)字符串,并報(bào)告它找到的第一個(gè)匹配。Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.search('super', 'superstition').span() 2 (0, 5) 3 >>> print re.search('super', 'insuperable').span() 4 (2, 7)Sometimes you'll be tempted to keep using re.match(), and just add .* to the front of your RE. Resist this temptation and use re.search() instead. The regular expression compiler does some analysis of REs in order to speed up the process of looking for a match. One such analysis figures out what the first character of a match must be; for example, a pattern starting with Crow must match starting with a "C". The analysis lets the engine quickly scan through the string looking for the starting character, only trying the full match if a "C" is found.有 時(shí)你可能傾向于使用 re.match(),只在RE的前面部分添加 .* 。請(qǐng)盡量不要這么做,最好采用 re.search() 代替之。正則表達(dá)式編譯器會(huì)對(duì) REs 做一些分析以便可以在查找匹配時(shí)提高處理速度。一個(gè)那樣的分析機(jī)會(huì)指出匹配的第一個(gè)字符是什么;舉個(gè)例子,模式 Crow 必須從 "C" 開(kāi)始匹配。分析機(jī)可以讓引擎快速掃描字符串以找到開(kāi)始字符,并只在 "C" 被發(fā)現(xiàn)后才開(kāi)始全部匹配。Adding .* defeats this optimization, requiring scanning to the end of the string and then backtracking to find a match for the rest of the RE. Use re.search() instead.添加 .* 會(huì)使這個(gè)優(yōu)化失敗,這就要掃描到字符串尾部,然后回溯以找到 RE 剩余部分的匹配。使用 re.search() 代替。3. Greedy versus Non-Greedy(貪婪 vs 不貪婪)When repeating a regular expression, as in a*, the resulting action is to consume as much of the pattern as possible. This fact often bites you when you're trying to match a pair of balanced delimiters, such as the angle brackets surrounding an HTML tag. The na?ve pattern for matching a single HTML tag doesn't work because of the greedy nature of .*.當(dāng)重復(fù)一個(gè)正則表達(dá)式時(shí),如用 a*,操作結(jié)果是盡可能多地匹配模式。當(dāng)你試著匹配一對(duì)對(duì)稱(chēng)的定界符,如 HTML 標(biāo)志中的尖括號(hào)時(shí)這個(gè)事實(shí)經(jīng)常困擾你。匹配單個(gè) HTML 標(biāo)志的模式不能正常工作,因?yàn)?.* 的本質(zhì)是“貪婪”的Toggle line numbersToggle line numbersToggle line numbers 1 >>> s = '' 2 >>> len(s) 3 32 4 >>> print re.match('<.*>', s).span() 5 (0, 32) 6 >>> print re.match('<.*>', s).group() 7 The RE matches the "<" in "", and the .* consumes the rest of the string. There's still more left in the RE, though, and the > can't match at the end of the string, so the regular expression engine has to backtrack character by character until it finds a match for the >. The final match extends from the "<" in ""to the ">" in "", which isn't what you want.RE 匹配 在 "" 中的 "<",.* 消耗掉子符串的剩余部分。在 RE 中保持更多的左,雖然 > 不能匹配在字符串結(jié)尾,因此正則表達(dá)式必須一個(gè)字符一個(gè)字符地回溯,直到它找到 > 的匹配。最終的匹配從 "<html" 中的 "<" 到 "" 中的 ">",這并不是你所想要的結(jié)果。In this case, the solution is to use the non-greedy qualifiers *?, +?, ??, or {m,n}?, which match as little text as possible. In the above example, the ">" is tried immediately after the first "<" matches, and when it fails, the engine advances a character at a time, retrying the ">" at every step. This produces just the right result:在這種情況下,解決方案是使用不貪婪的限定符 *?、+?、?? 或 {m,n}?,盡可能匹配小的文本。在上面的例子里, ">" 在第一個(gè) "<" 之后被立即嘗試,當(dāng)它失敗時(shí),引擎一次增加一個(gè)字符,并在每步重試 ">"。這個(gè)處理將得到正確的結(jié)果:Toggle line numbersToggle line numbersToggle line numbers 1 >>> print re.match('<.*?>', s).group() 2 (Note that parsing HTML or XML with regular expressions is painful. Quick-and-dirty patterns will handle common cases, but HTML and XML have special cases that will break the obvious regular expression; by the time you've written a regular expression that handles all of the possible cases, the patterns will be very complicated. Use an HTML or XML parser module for such tasks.)(注 意用正則表達(dá)式分析 HTML 或 XML 是痛苦的。變化混亂的模式將處理常見(jiàn)情況,但 HTML 和 XML 則是明顯會(huì)打破正則表達(dá)式的特殊情況;當(dāng)你編寫(xiě)一個(gè)正則表達(dá)式去處理所有可能的情況時(shí),模式將變得非常復(fù)雜。象這樣的任務(wù)用 HTML 或 XML 解析器。4. Not Using re.VERBOSE(不用 re.VERBOSE)By now you've probably noticed that regular expressions are a very compact notation, but they're not terribly readable. REs of moderate complexity can become lengthy collections of backslashes, parentheses, and metacharacters, making them difficult to read and understand.現(xiàn)在你可能注意到正則表達(dá)式的表示是十分緊湊,但它們非常不好讀。中度復(fù)雜的 REs 可以變成反斜杠、圓括號(hào)和元字符的長(zhǎng)長(zhǎng)集合,以致于使它們很難讀懂。For such REs, specifying the re.VERBOSE flag when compiling the regular expression can be helpful, because it allows you to format the regular expression more clearly.在這些 REs 中,當(dāng)編譯正則表達(dá)式時(shí)指定 re.VERBOSE 標(biāo)志是有幫助的,因?yàn)樗试S你可以編輯正則表達(dá)式的格式使之更清楚。The re.VERBOSE flag has several effects. Whitespace in the regular expression that isn't inside a character class is ignored. This means that an expression such as dog | cat is equivalent to the less readable dog|cat, but [a b] will still match the characters "a", "b", or a space. In addition, you can also put comments inside a RE; comments extend from a "#" character to the next newline. When used with triple-quoted strings, this enables REs to be formatted more neatly:re.VERBOSE 標(biāo)志有這么幾個(gè)作用。在正則表達(dá)式中不在字符類(lèi)中的空白符被忽略。這就意味著象 dog | cat 這樣的表達(dá)式和可讀性差的 dog|cat 相同,但 [a b] 將匹配字符 "a"、"b" 或 空格。另外,你也可以把注釋放到 RE 中;注釋是從 "#" 到下一行。當(dāng)使用三引號(hào)字符串時(shí),可以使 REs 格式更加干凈:Toggle line numbersToggle line numbersToggle line numbers 1 pat = re.compile(r""" 2 \s* # Skip leading whitespace 3 (?P[^:]+) # Header name 4 \s* : # Whitespace, and a colon 5 (?P.*?) # The header's value -- *? used to 6 # lose the following trailing whitespace 7 \s*$ # Trailing whitespace to end-of-line 8 """, re.VERBOSE)This is far more readable than:這個(gè)要難讀得多:Toggle line numbersToggle line numbersToggle line numbers 1 pat = re.compile(r"\s*(?P[^:]+)\s*:(?P.*?)\s*$")

總結(jié)

以上是生活随笔為你收集整理的python re的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

久久只精品99品免费久23小说 | av一级在线观看 | 国产精品美女毛片真酒店 | 久久久国产精品亚洲一区 | 国产精品视频app | 国产精品免费观看网站 | 一区二区三区视频网站 | 日韩在线观看你懂的 | 又粗又长又大又爽又黄少妇毛片 | 在线观看视频在线观看 | 成人观看 | 最近中文字幕高清字幕免费mv | 午夜视频99 | 精品一区二区在线免费观看 | 91成人在线免费观看 | 久久在线视频在线 | 日韩高清www| 天天爽人人爽夜夜爽 | 丁香婷婷网 | 亚洲九九九在线观看 | 色视频在线观看免费 | 久久99精品久久久久久秒播蜜臀 | 欧美精品免费在线观看 | 日韩乱理 | 97国产| 国产日韩亚洲 | 久久久免费观看 | 福利视频第一页 | 国产高清不卡一区二区三区 | 久久精品aaa | 日韩欧美一区二区三区免费观看 | 丝袜制服综合网 | 4hu视频| 99在线精品视频在线观看 | 成人久久18免费网站图片 | 狠狠操欧美 | 亚洲一区日韩精品 | 欧美韩日视频 | 午夜一级免费电影 | 91av影视 | 亚州av网站大全 | www操操| 国产精品一区二区久久久 | 久久伊人爱 | 毛片网站在线看 | 成人网在线免费视频 | 国产伦精品一区二区三区高清 | 日本精品一区二区三区在线观看 | 久久艹艹 | 免费看一级片 | 国产精品视频你懂的 | 精品美女国产在线 | 91精品播放 | 成人a毛片 | 在线看黄色av | 五月婷综合 | 中文av日韩 | 亚洲国产精品久久 | 免费的黄色的网站 | 国产精品久久一区二区无卡 | zzijzzij亚洲成熟少妇 | 视频三区在线 | 视频 天天草 | 久久免费观看视频 | 97福利在线 | 久久国产亚洲视频 | 亚洲成人资源在线观看 | 欧美色888 | 国产五月婷婷 | 亚洲精品在线一区二区三区 | 欧美中文字幕第一页 | 青青河边草免费观看完整版高清 | 丁香午夜| 亚洲精品 在线视频 | 亚洲国产午夜精品 | 在线导航福利 | 婷婷激情5月天 | 久草手机视频 | 欧美激情精品久久久久久 | 日韩在线资源 | 国内99视频 | av黄色在线观看 | 久久久久网址 | 久久久亚洲影院 | 久久夜色电影 | 欧美va在线观看 | 欧美一级视频免费看 | 在线观看国产日韩欧美 | 国产麻豆精品一区 | 亚洲男男gaygay无套同网址 | 激情久久久久 | 久久精品99国产精品 | 国产美女精品视频 | 在线a视频免费观看 | 看片一区二区三区 | 国内精品久久久久久久影视麻豆 | 我爱av激情网 | 一级淫片在线观看 | 亚洲国产经典视频 | 色夜视频 | 成人在线免费观看视视频 | 国产精品永久免费 | 精品久久久99 | 欧美精品乱码99久久影院 | 91精品第一页| 国产伦精品一区二区三区四区视频 | 在线播放一区二区三区 | 免费在线黄 | 欧美ⅹxxxxxx | 日本中文一级片 | 国产日韩精品一区二区在线观看播放 | 免费黄色av.| 日韩视频专区 | 亚洲精品中文字幕在线观看 | 婷婷色伊人 | 久久香蕉电影 | 91在线视频免费观看 | 亚洲欧美视频在线 | 日韩美一区二区三区 | 久久一区二区免费视频 | 日韩免费视频线观看 | 国产视频资源在线观看 | 国产成人在线网站 | 亚洲精品高清视频在线观看 | 国产精品免费在线播放 | 国产精品一区二区在线观看免费 | 欧美日韩免费在线视频 | 黄色福利网 | 国产成人亚洲精品自产在线 | 久久九九国产精品 | 色综合激情久久 | 国产一区二区免费看 | 国产夫妻av在线 | 国产精品美女久久久久久网站 | 911久久香蕉国产线看观看 | free. 性欧美.com | 久久国产一区二区三区 | 久久精品女人毛片国产 | 国产资源在线视频 | 亚洲自拍偷拍色图 | 国产成人精品一区二区三区福利 | 欧美色一色 | www.久久久 | 国产日本亚洲高清 | 精品欧美一区二区三区久久久 | 182午夜在线观看 | 亚洲aⅴ一区二区三区 | 亚洲一二三在线 | 人人玩人人添人人澡97 | 天天干天天在线 | 国产精品99久久久久久久久 | 日日婷婷夜日日天干 | 五月激情亚洲 | 91视频3p| 日韩精品一区二区三区丰满 | 999色视频 | 91精品一区二区在线观看 | 欧美极品xxxxx | 99亚洲精品 | 久久久99精品免费观看 | 国产免费久久精品 | 婷婷亚洲五月 | 永久中文字幕 | 久久婷婷色综合 | 日韩欧美在线第一页 | 中文字幕乱码亚洲精品一区 | 一级a性色生活片久久毛片波多野 | 精品久久久网 | 在线观看成人国产 | 免费看的国产视频网站 | 免费观看www7722午夜电影 | 国产精品永久在线 | 天天激情在线 | 午夜精品福利一区二区三区蜜桃 | 9999亚洲| 日韩电影一区二区在线观看 | 草久电影| 亚洲视频免费在线观看 | 中文字幕一区二区三区视频 | 欧美成人影音 | 久久久久久麻豆 | 久久久影院一区二区三区 | 日韩精品视频在线观看免费 | 国产五月婷 | 久久成人国产精品一区二区 | a久久久久久 | 国产精品一区二区三区四 | 天天艹天天干天天 | 国内精品久久久久久久影视麻豆 | 久久精品亚洲综合专区 | 国产一性一爱一乱一交 | 久久亚洲美女 | 五月激情五月激情 | 久草com| 国产剧情av在线播放 | 久久久网 | 97精品国产97久久久久久久久久久久 | 亚洲无吗天堂 | 91精品国产92久久久久 | 久久久免费毛片 | 99久久精品无码一区二区毛片 | 久久天天躁夜夜躁狠狠躁2022 | 中文字幕久久精品亚洲乱码 | 久久人人爽爽人人爽人人片av | 免费观看一级 | 亚洲精品久久在线 | 国产第一页精品 | 国产手机精品视频 | 国产精品正在播放 | 久久久久久麻豆 | 黄色中文字幕 | 精品一区二区久久久久久久网站 | 国产午夜精品理论片在线 | 欧美一区日韩一区 | 91免费视频国产 | 婷婷六月天天 | 日本中文字幕一二区观 | 一区二区电影网 | av免费片 | 亚洲精品www久久久 www国产精品com | 国产一二三四在线视频 | 91网站免费观看 | 国产精品久久99综合免费观看尤物 | 日韩经典一区二区三区 | 日韩欧美一区二区在线播放 | 国产精品不卡在线播放 | 在线视频18在线视频4k | 久久久99精品免费观看app | 97超碰伊人 | 亚洲精品乱码久久久久久 | 久久精品1区 | 制服丝袜欧美 | 国产免费观看视频 | 亚洲视频免费在线看 | 麻豆国产精品永久免费视频 | 国产免费叼嘿网站免费 | 色综合网 | 欧美日韩精品影院 | 蜜臀久久99静品久久久久久 | 亚州激情视频 | 国产精选在线观看 | 久热av在线| 国产精品久久久久三级 | 亚洲午夜在线视频 | 黄色一级免费网站 | 久久任你操 | 国产亚洲精品日韩在线tv黄 | 午夜精品久久久久99热app | 成人试看120秒 | 在线导航av | 久操久| 午夜精品久久久久久99热明星 | 日韩精品一区二区久久 | 精品国产观看 | 日韩在线视频线视频免费网站 | 国产精品视频久久久 | 成人av电影在线 | 久久视频这里有精品 | 97超碰国产精品 | 婷婷久久五月天 | 国产99久久久国产精品免费看 | 中文一区在线 | 精品国产99| 欧美一级艳片视频免费观看 | 天天射天天射天天射 | 久久五月婷婷综合 | 91福利小视频 | 久久久精品福利视频 | 亚洲最新视频在线播放 | 超碰97人人干 | aav在线| 在线 视频 一区二区 | 成年人免费在线观看网站 | 日日干夜夜草 | 24小时日本在线www免费的 | 亚洲欧美少妇 | 国产精品久久久久久久婷婷 | 91九色porn在线资源 | 日日干夜夜操视频 | 国产精品丝袜久久久久久久不卡 | 在线看不卡av | 婷婷丁香激情综合 | 亚洲天堂网站 | 欧美久久久久久久久久久 | 色综合久久88色综合天天6 | 欧美吞精| 日韩电影中文,亚洲精品乱码 | 丝袜美腿在线播放 | 天天亚洲 | 综合网欧美| 日韩精品一卡 | 日日夜夜国产 | 欧美日韩激情视频8区 | 日韩av女优视频 | 日本久久精 | 国产色综合 | 六月丁香婷婷久久 | 天天操夜操| 日日爽天天| 国产字幕在线观看 | 又色又爽又黄高潮的免费视频 | 精品极品在线 | 夜夜躁狠狠躁日日躁视频黑人 | 亚洲天天 | 国产无套精品久久久久久 | 久久精品国产一区二区电影 | 免费看黄色毛片 | 在线精品一区二区 | 欧美怡红院 | 成年人免费av网站 | 国产精品久久久久久一区二区 | 亚洲最快最全在线视频 | 免费的国产精品 | 日韩在线看片 | 国产一级淫片在线观看 | 成人免费视频a | 中文字幕91视频 | 久久兔费看a级 | 久久久噜噜噜久久久 | 友田真希x88av | 91在线视频免费91 | 国产亚洲免费观看 | 国产最新91| 国产在线精品区 | 狠狠躁夜夜a产精品视频 | 久久精品99精品国产香蕉 | 国产成人在线免费观看 | 99精品免费视频 | 久久99这里只有精品 | 日韩一区二区三区在线观看 | 麻豆国产露脸在线观看 | 91电影福利| 亚洲va天堂va欧美ⅴa在线 | 精品一二三区视频 | 日韩在线国产 | 久久婷婷国产色一区二区三区 | 久久色视频 | 色丁香婷婷 | 九九精品毛片 | av资源免费看 | 亚洲三级av | 不卡的一区二区三区 | 亚洲欧洲国产视频 | 欧美日韩精品在线视频 | 亚洲黄色激情小说 | 午夜精品一二三区 | 免费毛片一区二区三区久久久 | 九九热免费观看 | 九九热在线免费观看 | 国产在线精品一区二区不卡了 | 日韩欧美中文 | 中文字幕在线观看网 | 精品久久久久久亚洲综合网 | japanesexxxxfreehd乱熟 | 欧美福利在线播放 | 亚洲成人高清在线 | 日韩一级成人av | 天天爱天天操 | 黄色三级网站 | 久久99亚洲精品久久久久 | 中文视频一区二区 | 国产一区在线视频播放 | 日韩精品中文字幕在线播放 | 日韩免费b | 9ⅰ精品久久久久久久久中文字幕 | 欧美日韩在线观看一区二区三区 | 国内精品久久久久影院男同志 | 久久五月天综合 | 天堂视频中文在线 | 在线 精品 国产 | 91精品视频在线观看免费 | 日韩色一区二区三区 | 国产精品久久久久久久免费大片 | 中文字幕乱码亚洲精品一区 | 欧美一区二区精品在线 | 男女拍拍免费视频 | 久久免费的视频 | 98精品国产自产在线观看 | 国产一级视频 | 91香蕉视频在线下载 | 狠狠的操你 | 一区二区视频在线观看免费 | 中文字幕在线观看播放 | 欧美精品亚洲精品 | 激情婷婷久久 | 国产99久久精品一区二区300 | 中文字幕在线视频免费播放 | 亚洲国产精品影院 | 免费看国产视频 | 蜜臀久久99精品久久久久久网站 | 中文永久免费观看 | 91理论片午午伦夜理片久久 | 精品麻豆入口免费 | 一级性视频 | aaa免费毛片 | 夜夜躁日日躁狠狠久久av | 精品国产一区二区三区av性色 | 国产一级片在线播放 | 99精品视频免费全部在线 | 色综合久久88色综合天天免费 | 亚洲欧洲av在线 | 久久不卡国产精品一区二区 | 成人影视片 | 又长又大又黑又粗欧美 | 黄色在线视频网址 | 丁香av| 91亚洲永久精品 | av在线h| 国产亚洲精品久久久久久 | 激情视频免费在线 | 天天爽夜夜爽人人爽曰av | 久草在线最新免费 | 国产欧美精品xxxx另类 | 国产一区二区久久久 | 麻豆国产在线播放 | 91精品国产亚洲 | 国产麻豆精品95视频 | 国产成人一区在线 | 开心色婷婷 | 在线观看日韩一区 | 免费看的黄色片 | 国产一区二区不卡在线 | 成人久久视频 | 日本三级久久 | 免费国产一区二区视频 | 天天干天天摸天天操 | 久久久免费看片 | 91精品啪在线观看国产线免费 | 韩日精品视频 | 久色网| 99视频在线观看一区三区 | 蜜臀久久99静品久久久久久 | 国产97在线观看 | 97自拍超碰 | 婷婷色中文| 五月婷婷黄色网 | 成人h视频在线播放 | 国内揄拍国产精品 | 99久免费精品视频在线观看 | 中文字幕制服丝袜av久久 | 国产精品12345| 国产在线精品区 | 精品久久免费看 | 婷婷综合激情 | 久久久精品久久 | 国产精品第一页在线 | 在线免费av网站 | 久久成人在线 | 亚洲黄色精品 | 亚洲特级片| 国产精品久久久久影院 | 色综合久久久久 | 99欧美视频 | 一区二区三区韩国免费中文网站 | 69精品视频| 成人在线免费观看网站 | 2023av在线| 在线观看中文字幕2021 | 日韩综合一区二区 | 在线亚洲激情 | www.久久久精品 | 久草在线视频在线观看 | 99国产视频在线 | 欧美日韩不卡在线观看 | 天天综合天天做 | av国产在线观看 | 国产免费中文字幕 | 久久福利小视频 | 欧美日韩一区二区在线 | 成年人免费观看在线视频 | 日本动漫做毛片一区二区 | 色综合久久88色综合天天人守婷 | 日日干干 | 麻豆av一区二区三区在线观看 | 麻豆极品 | 在线观看av小说 | 亚洲国产精彩中文乱码av | 成人在线一区二区 | av中文字幕网 | 亚洲 综合 激情 | 中文字幕乱码日本亚洲一区二区 | 久久久久久久影院 | www色网站| 欧美精品一区在线 | 亚洲婷婷伊人 | 久久精品影视 | 色吊丝在线永久观看最新版本 | 黄色免费观看网址 | 在线看不卡av | 九九热久久久 | 97在线公开视频 | 奇米四色影狠狠爱7777 | 园产精品久久久久久久7电影 | 五月婷婷免费 | 免费网址在线播放 | 久久久国产99久久国产一 | 曰韩在线 | 成人av资源网| 97精品国产91久久久久久 | 99久久久久久久 | 日韩一区二区久久 | 97免费视频在线播放 | 天天干天天插伊人网 | 好看av在线 | jizz18欧美18| 久久中文字幕在线视频 | 在线观看小视频 | 日韩免费观看一区二区 | 不卡的av在线播放 | 一级片免费视频 | 热久久影视 | 在线观看av免费 | 久久久久久久久久久久亚洲 | 麻豆免费在线视频 | 久草视频在线资源 | 99精品在线| 天天色天天色天天色 | 中文字幕成人 | 亚洲精品视频 | av大片网址| 欧美日韩不卡在线视频 | 一区二区三区久久 | 97视频免费观看2区 亚洲视屏 | 久久视频在线观看 | 狠狠色噜噜狠狠狠狠2021天天 | 天堂av观看| 蜜臀av一区二区 | 久草视频免费在线观看 | 91精品久久久久久久99蜜桃 | 久久草草热国产精品直播 | 超碰在线91 | 日本在线观看黄色 | 91精品福利在线 | 九九久久国产 | 精品国产一区二区三区av性色 | 九九免费在线看完整版 | 2021国产在线视频 | 免费观看国产精品 | 99视频导航 | 1区2区3区在线观看 三级动图 | 国产成人一区二区三区影院在线 | 999在线精品 | 96av视频| 亚洲91网站| 成人在线黄色 | 99精品福利| 欧美精品一区在线发布 | 天天爱天天射天天干天天 | 性日韩欧美在线视频 | 精品成人网 | 国产午夜精品av一区二区 | 九九久久国产 | 字幕网av | 国产成视频在线观看 | 亚洲国产久 | 日日夜夜免费精品视频 | 黄色大全免费网站 | 久久国产精品99久久久久久老狼 | 久久精品韩国 | 国产成人av免费在线观看 | 伊甸园av在线 | 亚洲日本成人 | 四虎5151久久欧美毛片 | 99精品黄色片免费大全 | 国产午夜精品免费一区二区三区视频 | 在线播放视频一区 | 精品国内自产拍在线观看视频 | 91免费高清在线观看 | 色www免费视频 | 国产精品久久久电影 | 日日夜夜狠狠操 | 亚洲最大成人免费网站 | 国产精品久久久久久久久久不蜜月 | 99热这里精品 | 色综合五月 | 久久免费国产精品 | 欧美视频一区二 | 97视频在线观看视频免费视频 | 久久免费精品国产 | 久草视频在线免费看 | 96精品视频 | 国产日韩欧美网站 | 一级黄色大片在线观看 | 一级欧美一级日韩 | 国产精品美女久久久久久免费 | 国产精选在线观看 | 成人在线播放av | 国产精品毛片完整版 | 国产高清免费视频 | 欧美日韩国产欧美 | 国产精品日韩在线播放 | 国产午夜视频在线观看 | 亚洲精色| 亚洲天天做| 久久成人人人人精品欧 | 在线免费视| 91完整版在线观看 | av成人免费在线观看 | 日本一区二区三区视频在线播放 | 欧美一性一交一乱 | 成人av一区二区兰花在线播放 | 91香蕉国产在线观看软件 | 日韩欧美精品在线视频 | 中文字幕在线久一本久 | 狠狠操狠狠操 | 丁香六月婷婷开心婷婷网 | 激情网五月婷婷 | 国产精品久久久久久电影 | 五月天高清欧美mv | 天天操天天操天天干 | 免费99视频| 亚洲砖区区免费 | 欧美久久综合 | 国产一线天在线观看 | 在线观看日韩av | 亚洲黄色在线观看 | 亚洲精品久久久久中文字幕m男 | 日韩精品欧美精品 | 欧美精品天堂 | 丁香导航 | 亚洲精品毛片一级91精品 | 国产精品成人自产拍在线观看 | 天天射综合网站 | 日韩一二三在线 | 成人精品亚洲 | 久久国产精品一区二区三区 | 天天综合色网 | 日本午夜在线亚洲.国产 | 国产亚洲视频在线 | 九九热视频在线免费观看 | 亚洲精品视频www | 亚洲精选视频在线 | 欧美日本一二三 | 色一级片 | 免费视频网 | 狠狠狠干狠狠 | 久久久久久久国产精品视频 | 偷拍精偷拍精品欧洲亚洲网站 | 日日夜夜精品网站 | 成人97视频一区二区 | 久久精品这里都是精品 | av免费看网站 | 超碰在线公开免费 | 国产黄在线播放 | 亚洲综合欧美精品电影 | 99久久这里有精品 | 亚洲欧洲美洲av | 色噜噜在线观看 | 五月开心激情网 | 丁香5月婷婷 | 亚洲国产免费看 | 中文字幕第一页在线视频 | 日韩和的一区二在线 | 欧美日韩视频在线播放 | 久久综合五月天婷婷伊人 | 成人h动漫精品一区二 | 中文字幕在线乱 | 天天干.com | 免费在线中文字幕 | 久久99久久99精品免观看软件 | 亚洲手机av| av3级在线 | 国产高清视频在线播放 | 国产午夜精品久久 | 国产精品乱码一区二区视频 | 美女网站在线 | www.久草.com | 亚州精品天堂中文字幕 | 九九精品久久 | 欧美伦理一区 | 五月天狠狠操 | 婷婷丁香五 | 91中文视频 | 亚欧洲精品视频在线观看 | 成人av网址大全 | 最新av观看 | 91桃色视频 | 国产青青青 | 中文字幕在线观看免费高清完整版 | 91精品导航 | 免费看十八岁美女 | 亚洲国产网站 | 在线成人一区二区 | 国产免费作爱视频 | 亚洲成av人电影 | 色播激情五月 | 91精品成人久久 | 久久精选 | 三级av网| www.精选视频.com | 亚洲精品欧美成人 | 一本到在线| 成人网444ppp| 日韩在线中文字幕 | 亚洲 中文 欧美 日韩vr 在线 | 韩日色视频 | 欧美成年黄网站色视频 | 免费一级片观看 | 精品毛片在线 | 亚洲精品乱码久久久久久蜜桃动漫 | 国产麻豆精品一区二区 | 久久精品99久久久久久2456 | 97视频在线观看播放 | 国产精品免费久久 | 免费在线观看成人小视频 | 国产一级片直播 | 91av亚洲| 天天天操操操 | 欧美精选一区二区三区 | 91av欧美| 日韩精品国产一区 | 中文字幕亚洲精品在线观看 | 欧美日韩激情视频8区 | 就操操久久 | 亚洲va男人天堂 | 久久视频免费观看 | 国际精品久久久久 | 午夜三级在线 | 99热精品国产一区二区在线观看 | 99视频精品免费视频 | 91精品国产自产在线观看 | 国产精品久久久久久欧美 | 亚一亚二国产专区 | 久久综合精品国产一区二区三区 | 亚洲精品理论片 | 欧美日韩视频在线播放 | 婷婷丁香激情网 | 久久精品视频免费 | a在线视频v视频 | 99久热在线精品视频 | 国产成人精品国内自产拍免费看 | 手机在线黄色网址 | 免费看的黄网站 | 精品一区二区久久久久久久网站 | 国产精品亚洲片在线播放 | 免费a网址 | 免费视频久久久 | 色欲综合视频天天天 | 国产福利av在线 | 在线观看视频99 | 玖玖在线免费视频 | 久久综合影音 | 日韩av免费观看网站 | 91在线精品观看 | 免费国产黄线在线观看视频 | 亚洲视频高清 | 色噜噜狠狠狠狠色综合 | 香蕉视频免费看 | 99这里只有 | 亚洲欧洲国产精品 | 午夜视频欧美 | 国产精品久久电影观看 | 又黄又爽又色无遮挡免费 | 一级性生活片 | 麻豆成人小视频 | 成人中文字幕+乱码+中文字幕 | 国产精品一区二区三区四 | 九九有精品 | 国产精品国产三级国产不产一地 | 免费看黄的 | 美女免费黄视频网站 | 亚洲国产精品久久久久久 | 日韩大片免费观看 | av+在线播放在线播放 | 91超在线| 亚洲精品一区二区18漫画 | av线上免费看 | 国产精品永久免费在线 | 日本三级在线观看中文字 | 久久久久国产精品厨房 | 在线播放 亚洲 | 欧美一级免费片 | 亚洲精品美女久久久久网站 | 欧美另类老妇 | 欧美精品在线一区 | 九热精品 | 国产精品igao视频网入口 | 久久免费成人精品视频 | 欧美性生活久久 | 色美女在线 | 99精品欧美一区二区三区黑人哦 | 久久国产日韩 | 热久久这里只有精品 | 99视频在线免费播放 | 国产亚洲婷婷免费 | 久草在 | 91精品国产高清自在线观看 | 丰满少妇在线 | 97福利| 337p日本欧洲亚洲大胆裸体艺术 | 久久情侣偷拍 | 久久观看最新视频 | 国产香蕉97碰碰碰视频在线观看 | 在线观看国产区 | 国产精品一区二区三区在线播放 | 在线影院中文字幕 | 日韩中文字幕免费电影 | 免费a级观看 | 狠狠狠狠狠狠操 | 国产视频欧美视频 | 狠狠色丁香婷婷综合橹88 | 特级xxxxx欧美 | 精品色999 | 国产精品一区二区三区四 | 国产经典av | 精品少妇一区二区三区在线 | 国产精品乱码久久久久 | 中文字幕在线观看三区 | 亚洲电影久久 | 久久久黄视频 | 国产一区二区视频在线 | 欧美小视频在线观看 | 天天操天天摸天天射 | 在线免费观看一区二区三区 | 日日成人网 | 91大神精品视频在线观看 | 国产精品3 | 人人澡人人模 | 麻花天美星空视频 | 91九色蝌蚪在线 | 一区二区三区av在线 | 天堂av免费看 | av在线免费在线观看 | 俺要去色综合狠狠 | 国产精品一区二区久久久久 | 国产一区在线观看免费 | 久久婷婷国产色一区二区三区 | 综合网色 | 亚洲欧美国产视频 | 五月激情综合婷婷 | 在线成人免费 | 国产精品自拍在线 | 99视频精品| 在线高清av | 日韩精选在线观看 | 中文字幕av全部资源www中文字幕在线观看 | 欧美日韩免费在线观看视频 | 8x8x在线观看视频 | 亚洲人成精品久久久久 | 手机av在线网站 | 亚洲一级黄色av | 91激情| 不卡的av中文字幕 | 天天摸天天干天天操天天射 | 久久精品欧美视频 | 日韩专区在线观看 | 久草在线免费资源站 | 中文字幕在线播放一区 | 欧美激情xxxx | 麻豆av一区二区三区在线观看 | 国产精品久久久久久久久久久久午夜片 | 精品国产一区二区三区久久影院 | 99精品视频免费全部在线 | 国产精品电影一区 | 国产一级二级在线观看 | 91xav| 福利视频导航网址 | 最新av电影网站 | 中文字幕日韩电影 | 久久少妇免费视频 | 国产精品69久久久久 | 黄免费在线观看 | 欧美九九视频 | 亚洲精品456在线播放乱码 | 亚洲免费国产视频 | 在线免费日韩 | 国内精品福利视频 | 91黄色影视 | 色婷婷综合成人av | 99在线精品免费视频九九视 | 国产精品1024 | 日韩午夜大片 | 91麻豆免费视频 | 天堂素人在线 | 又爽又黄在线观看 | 午夜精品一区二区国产 | 99热这里精品| 国产精品一区二区免费在线观看 | 欧美激情精品久久久久久免费印度 | 黄色日本免费 | 成年人电影毛片 | 国产综合香蕉五月婷在线 | 婷婷六月综合网 | 456成人精品影院 | 国精产品一二三线999 | 天堂视频一区 | 国产成人99久久亚洲综合精品 | 欧美韩日在线 | 91xav| 在线观看中文字幕 | 欧洲精品在线视频 | 成人免费观看在线视频 | 久久视频免费在线 | 深爱激情五月网 | 夜色资源站国产www在线视频 | 久久精品国产免费 | 亚洲国产日韩一区 | 18国产精品白浆在线观看免费 | 九九导航 | 色夜视频| 青青河边草观看完整版高清 | 国产精品久久久亚洲 | www.天天操 | 国产成人三级三级三级97 | 五月婷婷免费 | 久久国产精品免费一区二区三区 | 91男人影院| 欧美精品成人在线 | 欧美一区三区四区 | 精品自拍av| 开心激情五月婷婷 | 激情久久综合网 | 九色琪琪久久综合网天天 | 久久婷婷精品视频 | 中日韩三级视频 | 亚洲国产午夜视频 | 一区二区三区免费在线观看 | 午夜精品电影 | 蜜臀91丨九色丨蝌蚪老版 | 99色在线观看视频 | 精品亚洲二区 | 操操操日日日干干干 | 久草网视频 | 天天在线免费视频 | 黄网站色欧美视频 | 91人人揉日日捏人人看 | 国产精品久久久久久久久久久久 | 91亚洲精品久久久蜜桃网站 | 欧美狠狠色 | 免费 在线 中文 日本 | 国内久久视频 | 亚洲精品五月天 | 婷婷综合视频 | 天天摸夜夜添 | 6699私人影院 | 成年人黄色大片在线 | 亚洲视频高清 | 91中文在线视频 | 97精品国产97久久久久久春色 | 日日干天天爽 | 免费高清av在线看 | 日本美女xx | 一区二区三区在线免费观看 | www视频在线播放 | 欧美日韩国产色综合一二三四 | 国产成人在线看 | 一区二区三区高清 | 精品国产伦一区二区三区观看方式 | 欧美国产日韩一区二区三区 | 国产手机av | 亚洲精品tv久久久久久久久久 | 四虎影视8848aamm| 国产精品高潮在线观看 | 精品视频免费在线 | 国产成人在线看 | 奇米影视四色8888 | 欧美精品日韩 | 欧美日韩在线免费观看 | 日韩精品你懂的 | 丁香婷五月 | 丰满少妇麻豆av | 欧美福利在线播放 | 性色av香蕉一区二区 | 国产美女精品久久久 | 国产成人免费高清 | 久久99国产精品视频 | 亚洲国产欧美在线看片xxoo | 亚洲精品国产拍在线 | 亚洲专区视频在线观看 | 亚洲五月激情 | 中文字幕在线视频第一页 | 亚洲一区二区三区精品在线观看 | 黄色三级在线看 | 91丨九色丨高潮丰满 | 一区二区三区视频网站 | 国产资源免费在线观看 | 国产精品热| 亚洲精品乱码久久久久久蜜桃欧美 | 欧美精品久久久久久久久免 | 91麻豆精品国产自产 | 色偷偷网站视频 | 精品av网站 | 久久久久欧美精品 | 九九欧美视频 | 久久综合射 | 色婷婷av国产精品 | 日韩成人在线一区二区 | 中文字幕av在线播放 | 五月婷婷黄色 | 欧美黑人猛交 | 日韩欧美一区二区三区在线 | 四虎最新入口 | 黄色软件视频大全免费下载 | 五月视频| 国产精品 日韩 欧美 | 国产不卡毛片 | 国产香蕉97碰碰久久人人 | 日本电影黄色 |