English 中文(简体)
2. 清洁沙尘定期表达
原标题:
  • 时间:2009-06-06 02:21:57
  •  标签:

难道有更清洁的方法来撰写长时期的 p格模式吗? 我在某些地方看到了这种做法,但是,在登峰造册中,这种做法是允许的。

patterns = [
    re.compile(r <!--([^->]|(-+[^->])|(-?>))*-{2,}> ),
    re.compile(r 
+|s{2} )
]
最佳回答

你们可以采用两种手法的方式来撰写更可读的定期表述。 以这种方式:

  • Whitespace within the pattern is ignored, except when in a character class or preceded by an unescaped backslash.
  • When a line contains a # neither in a character class or preceded by an unescaped backslash, all characters from the leftmost such # through the end of the line are ignored.

以下两份声明均相同:

a = re.compile(r"""d +  # the integral part
                   .    # the decimal point
                   d *  # some fractional digits""", re.X)

b = re.compile(r"d+.d*")

(摘自verbose Mode)

问题回答

虽然@Ayman关于<代码>的建议。 如果你想要的是你所再次显示的话,光是:

patterns = re.compile(
        r <!--([^->]|(-+[^->])|(-?>))*-{2,}> 
        r 
+|s{2} 
)

甲型六氯环己烷和甲型六氯环己烷的自动分类(如C s,btw)将替代物。

你们可以把评论用在册子里,从而使它们更容易阅读。 http://gnosis.cx/publish/programming/table_expressions.html”

/               # identify URLs within a text file
          [^="] # do not match URLs in IMG tags like:
                # <img src="http://mysite.com/mypic.png">
http|ftp|gopher # make sure we find a resource type
          :// # ...needs to be followed by colon-slash-slash
      [^ 

]+ # stuff other than space, newline, tab is in URL
    (?=[s.,]) # assert: followed by whitespace/period/comma 
/




相关问题
热门标签