바로 마음속 으로 터득 하 다

6665 단어 정칙
}


ati('#', 'http://www.cnblogs.com/../UpLoadFile/Product/20101010162153846.jpg',' 두 꺼 운 파란색 목도리 ');
줄 바 꿈 문자 와 일치 해 야 합 니 다.
아래 와 같이 사용 합 니 다.
\s\sati
여기 서 \ s 두 개 를 사용 하 는 것 은 \ r 와 일치 하 는 원인 일 것 입 니 다.
\ s * 도 사용 할 수 있 습 니까?더 통용 되 는 효 과 를 얻 을 수 있 습 니 다.
[\ s \ S] * 에 지나치게 의존 하면 역 추적 인용 을 초래 하여 프로그램 을 죽 일 수 있 습 니 다. 위 는 제 가 개선 한 프로그램 입 니 다. 예전 에 프로그램 이 계속 걸 려 있 었 습 니 다. 원래 그것 은 모두 [\ s \ S] * 를 사 용 했 습 니까?저장 하지 않 았 습 니 다. [^] * 를 사용 하여 대체 하 는 것 을 권장 합 니 다.
쓰다
[\s\s]*?... 이 아니 라
[\s\s]*?re.
finditer
(
pattern,
string
[,
flags
]
)

Return an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in string. The string is scanned left-to-right, and matches are returned in the order found. Empty matches are included in the result unless they touch the beginning of another match.
 
 
 
 
7.2.6.9. Raw String Notation
Raw string notation (r"text") keeps regular expressions sane. Without it, every backslash ('\') in a regular expression would have to be prefixed with another one to escape it. For example, the two following lines of code are functionally identical:
>>> re.match(r"\W(.)\1\W", " ff ")
<_sre.SRE_Match object at ...>
>>> re.match("\\W(.)\\1\\W", " ff ")
<_sre.SRE_Match object at ...>

When one wants to match a literal backslash, it must be escaped in the regular expression. With raw string notation, this means r"\\". Without raw string notation, one must use "\\\\", making the following lines of code functionally identical:
>>> re.match(r"\\", r"\\")
<_sre.SRE_Match object at ...>
>>> re.match("\\\\", r"\\")
<_sre.SRE_Match object at ...>


20101015更新
对于诸如

       
       <div class="listPic"><a href="/?mod=goods&amp;do=display&amp;id=2032&amp;sid=f11ee838a106889a37abf4e9227a03fe" target="_blank"><img src='/upload/photobase/2010-09/100924112121_s.jpg' border="0" title="新款 银色小雏菊三叶草满钻白色珍珠开口戒指" /></a>
的匹配,我们可以使用如下的回溯引用来达到前后一致匹配的效果,这里还要注意,以括号命名的就是名组,只不过类似link,img是named group,另一种(‘|”)未显式的标识出来,但都占用数字位从1开始,因此,    1          2       这个不占                      3           4        
<div class="listPic"><a[\s\S]*?href=("|')(?P<link>[^"]*?)\1[\s\S]*?<img[\s\S]*?src=("|')(?P<img>[^"]*?)\3

좋은 웹페이지 즐겨찾기