Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Python Re

1. Basic
²Î¿¼¡¶PythonÕýÔò±í´ïʽ²Ù×÷Ö¸ÄÏ¡· 
Ä£¿ére£¬perl·ç¸ñµÄÕýÔò±í´ïʽ
regex²¢²»Äܽâ¾öËùÓеÄÎÊÌ⣬ÓÐʱºò»¹ÊÇÐèÒª´úÂë
regex»ùÓÚÈ·¶¨ÐԺͷÇÈ·¶¨ÐÔÓÐÏÞ×Ô¶¯»ú
2. ×Ö·ûÆ¥Åä(Ñ­Ðò½¥½ø)
Ôª×Ö·û
. ^ $ * + ? { [ ] \ | ( )
1) "[" ºÍ "]"³£ÓÃÀ´Ö¸¶¨Ò»¸ö×Ö·ûÀà±ð£¬Ëùν×Ö·ûÀà±ð¾ÍÊÇÄãÏëÆ¥ÅäµÄÒ»¸ö×Ö·û¼¯¡£Èç[abc]»òÕß[a-c]¡£Àà±ðÖв»Ðè·Ö¸ô·ûÖ®ÀàµÄ¶«Î÷
Ôª×Ö·ûÔÚÀà±ðÀï²¢²»Æð×÷Óá£ÀýÈ磬[akm$]½«Æ¥Åä×Ö·û"a", "k", "m", »ò "$" ÖеÄÈÎÒâÒ»¸ö£»"$"ͨ³£ÓÃ×÷Ôª×Ö·û£¬µ«ÔÚ×Ö·ûÀà±ðÀÆäÌØÐÔ±»³ýÈ¥£¬»Ö¸´³ÉÆÕͨ×Ö·û¡£
2) ^
²¹¼¯¡£°Ñ"^"×÷ΪÀà±ðµÄÊ׸ö×Ö·û£»ÆäËüµØ·½µÄ"^"Ö»»á¼òµ¥Æ¥Åä "^"×Ö·û±¾Éí¡£ÀýÈ磬[^5] ½«Æ¥Åä³ý "5" Ö®ÍâµÄÈÎÒâ×Ö·û¡£
3) \
ºÜÅ££¡
\d  Æ¥ÅäÈκÎÊ®½øÖÆÊý£»ËüÏ൱ÓÚÀà [0-9]¡£
\D  Æ¥ÅäÈκηÇÊý×Ö×Ö·û£»ËüÏ൱ÓÚÀà [^0-9]¡£
\s  Æ¥ÅäÈκοհ××Ö·û£»ËüÏ൱ÓÚÀà  [ \t\n\r\f\v]¡£
\S  Æ¥ÅäÈκηǿհ××Ö·û£»ËüÏ൱ÓÚÀà [^ \t\n\r\f\v]¡£
\w  Æ¥ÅäÈκÎ×ÖĸÊý×Ö×Ö·û£»ËüÏ൱ÓÚÀà [a-zA-Z0-9_]¡£
\W  Æ¥ÅäÈκηÇ×ÖĸÊý×Ö×Ö·û£»ËüÏ൱ÓÚÀà [^a-zA-Z0-9_]¡£
4) .
 . Æ¥Åä³ýÁË»»ÐÐ×Ö·ûÍâµÄÈκÎ×Ö·û£¬ÔÚ alternate ģʽ£¨re.DOTALL£©ÏÂËüÉõÖÁ¿ÉÒÔÆ¥Åä»»ÐС£"." ͨ³£±»ÓÃÓÚÄãÏëÆ¥Åä“ÈκÎ×Ö·û”µÄµØ·½¡£
3. Öظ´
1) *
Æ¥Åä0~n¸ö×Ö·û£¬Ò»°ã²»³¬¹ý×î´óÊý
ÕâÖÖÖظ´ÊÇ“Ì°À·µÄ”
×÷ÓÃÓÚÇ°Ò»¸öÀà±ð»òÕß×Ö·û¡£Èçca*t×÷ÓÃÓÚa£¬a[bc]*d×÷ÓÃÓÚ[bc]
2) +
Æ¥Åä1~n
3) ?
Æ¥Åä0~1
4) {m, n}
ÆäÖÐ m ºÍ n ÊÇÊ®½øÖÆÕûÊý¡£¸ÃÏÞ¶¨·ûµÄÒâ˼ÊÇÖÁÉÙÓÐ m ¸öÖظ´£¬ÖÁ¶àµ½ n ¸öÖظ´¡£¾Ù¸öÀý×Ó£¬a/{1,3}b ½«Æ¥Åä "a/b"£¬"a//b" ºÍ "a///b"¡£Ëü²»ÄÜÆ¥Åä "ab" ÒòΪûÓÐб¸Ü£¬Ò²²»ÄÜÆ¥Åä "a////b" £¬ÒòΪÓÐËĸö¡£
ÆäËûÈý¸öÏÞ¶¨·û¶¼¿ÉÒÔÓÃÕâÑù·½Ê½À´±íʾ¡£ {0,} µÈͬÓÚ *£¬{1,} µÈͬÓÚ +£¬¶ø{0,1}ÔòÓë ? Ïàͬ¡£Èç¹û¿ÉÒԵĻ°£¬×îºÃʹÓà *£¬+£¬»ò?¡£ºÜ¼òµ¥ÒòΪËüÃǸü¶ÌÒ²ÔÙÈÝÒ׶®¡£×îºó×ÜÄÜÕâÑù£¬ÓиöͬһµÄ
4. Àý×Ó
1) Éú³ÉRE
import re
#RE is a string
p = re.compile('[a-z]+')
print p
2)ʹÓÃ
if p.match(''):
    print 'matched'
else:
    print 'not matched'
#results: not matched
3) ·µ»ØÖµ
m = p.match('abcdef')
if m:
    print 'matched again'
else:
    print 'no


Ïà¹ØÎĵµ£º

Pythonѧϰ×ÊÁÏ


Pythonѧϰ
 
»ù±¾ÄÚÈÝ
Python»ù±¾°²×°£º
http://www.python.org/ ¹Ù·½±ê×¼Python¿ª·¢°üºÍÖ§³Ö»·¾³£¬Í¬Ê±Ò²ÊÇPythonµÄ¹Ù·½ÍøÕ¾£»
http://www.activestate.com/ ¼¯³É¶à¸öÓÐÓòå¼þµÄÇ¿´ó·Ç¹Ù·½°æ±¾£¬ÌرðÊÇÕë¶ÔWindows»·¾³Óв»ÉٸĽø£»
 
PythonÎĵµ£º
http://www.python.org/doc/current/lib/ ......

PythonÖеĴúÂëÖØÓ×—Modules

      ÔÚPythonÖУ¬¿ÉÒÔʹÓÃFunctionÀ´ÊµÏÖ´úÂëÖØÓá£Èç¹ûÐèÒªÖØÓÃÒ»×éfunction£¬ÔòÐèҪʹÓÃModules¡£
      ¶ÔÓÚModules£¬¿ÉÒÔʹÓÃÁ½ÖÖ·½·¨±àд¡£µÚÒ»¡¢Ò²ÊÇ×î¼òµ¥µÄ·½·¨£¬¾ÍÊÇʹÓÃPython±àд¡£¿ÉÒÔ´´½¨Ò»¸öºó׺ÃûΪ.pyµÄÎļþ£¬ÔÚÆäÖбàдº¯ÊýºÍ±äÁ¿¡£ÁíÍâÒ»ÖÖ·½·¨ÊÇÖ ......

PythonÊý¾Ý½á¹¹Ö®——list

     PythonÖÐÓÐËÄÖÖÄÚ½¨µÄÊý¾Ý½á¹¹£ºList£¬Tuple£¬Dictionary£¬Set¡£±¾ÎÄÖ÷Òª½éÉÜList¡£
     ListÊÇÓÃÀ´´æ·ÅÒ»×é¶ÔÏóÐòÁС£¿ÉÒÔÏñlistÖÐÌí¼ÓÔªËØ¡¢É¾³ýÔªËØ£¬Í¬Ê±Ò²¿ÉÒÔÏñ·ÃÎÊÊý×éÒ»Ñù·ÃÎÊlist¡£ListÊǿɱäµÄÊý¾ÝÀàÐÍ¡£
    ÏÂÃ棬¸ø³öÒ»×élistµÄÊ¹Ó ......

PythonÖÐsocketºÍ¶àÏ̵߳ÄÓ¦ÓÃ

ÕâÊÇÎÒÒÔǰдµÄÒ»¸ösocketСӦÓã¬ÆäÖÐҲ˳±ãÓõ½ÁËÒ»µãµã¶àÏ̵߳Ķ«Î÷¡£
Õâ¸ösocket¿Í»§¶ËÊÇÎÒΪÁË·½±ã¹«Ë¾µÄ³äֵϵͳµ÷ÊÔ¶øдµÄÒ»¸öСӦÓá£ÓÉËü¸ú³äֵϵͳ½øÐÐsocketͨѶ£¬×Ô¶¯Íê³É³äÖµµÄ²âÊÔ¹¤×÷¡£
¿´´úÂë°É£º
import socket,thread
def Communicate(s):
phoneno = raw_input("Please input your PhoneNo.:(Pu ......

pythonÖеĶàÏß³Ì


2007-07-15
pythonÖеĶàỊ̈߳¨2£©
¹Ø¼ü×Ö: python thread threading
    ÎÒÃÇÔÚÉÏÒ»ÕÂÖп´µ½Ê¹ÓÃthreading.Thread.join()¿ÉÒÔ±ÜÃâÖ÷³ÌÐòÔڵȴýÆäËüÏ߳̽áÊøµÄ¹ý³ÌÖеõ½Ê±¼äƬ¡£ÊÂʵÉÏ£¬ÔÚÏ̱߳à³ÌÖо­³£»áÓöµ½Ò»¸öÏß³ÌÐèÒªµÈ´ýÁíÒ»¸öÏß³ÌÖеÄÇé¿ö¡£ÔÚÕâÖÖÇé¿öÏ£¬ÐèÒªÖØÉêµÄÊÇ£¬ÎÒÃDz»Ï£ÍûµÈ´ýµÄÏß³ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ