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

python ÕýÔò±í´ïʽºÍreÄ£¿é

ÕýÔò±í´ïʽÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄÒ»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨.
ÕýÔò±í´ïʽ£¨»ò RE£©ÊÇÒ»ÖÖСÐ͵ġ¢¸ß¶Èרҵ»¯µÄ±à³ÌÓïÑÔ£¬£¨ÔÚPythonÖУ©ËüÄÚǶÔÚPythonÖУ¬²¢Í¨¹ý re Ä£¿éʵÏÖ.×Ö·û´®Ò²Óкܶ෽·¨,¿ÉÒÔ½øÐÐËÑË÷ (index¡¢find ºÍ count)¡¢Ìæ»» (replace) ºÍ½â
Îö (split),µ«ËüÃǽöÏÞÓÚ´¦Àí×î¼òµ¥µÄÇé¿ö
re Ä£¿éʹ Python ÓïÑÔÓµÓÐÈ«²¿µÄÕýÔò±í´ïʽ¹¦ÄÜ¡£ compile º¯Êý¸ù¾ÝÒ»¸öģʽ×Ö·û´®ºÍ¿ÉÑ¡µÄ±êÖ¾²ÎÊýÉú³ÉÒ»¸öÕýÔò±í´ïʽ¶ÔÏ󡣸öÔÏóÓµÓÐһϵÁз½·¨ÓÃÓÚÕýÔò±í´ïʽƥÅäºÍÌæ»»¡£
³£ÓÃÕýÔò±í´ïʽ
'.*' ×÷Ϊһ¸öÕýÔò±í´ïʽƬ¶Î±íʾ "ÈÎÒâ¸öÊý(0»ò¸ü¶à¸ö)µÄÈÎÒâ×Ö·û(³ý»»ÐÐÍâ)"¡£Ò²¾ÍÊÇ˵£¬ '.*' Æ¥ÅäÒ»¸ö×Ö·û´®ÖеÄÈÎÒâ×Ó´®£¬°üÀ¨¿Õ´®¡£
'.+' Óë'.*'ÀàËÆ£¬²»¹ýËü²»°üÀ¨¿Õ´®
ҪǿÖÆÒ»¸öģʽ½öÆ¥ÅäÓÉ 'post' ½áβµÄ×Ö·û´®£¬Óà \Z ½áÊøÕâ¸öģʽ¡£¾ÍÏóÏÂÃæÕâÑù£º
r'pre.*post\Z'
Æ¥Åä 'prepost', µ«²»Æ¥Åä 'preposterous'.
ģʽ×Ö·û´®Óï·¨
ģʽ×Ö·û´®Ê¹ÓÃÌØÊâµÄÓï·¨À´±íʾһ¸öÕýÔò±í´ïʽ£º
¶àÊý×ÖĸºÍÊý×ÖÇ°¼ÓÒ»¸ö·´Ð±¸Üʱ»áÓµÓв»Í¬µÄº¬Òå¡£
±êµã·ûºÅÖ»Óб»×ªÒåʱ²ÅÆ¥Åä×ÔÉí£¬·ñÔòËüÃDZíʾÌØÊâµÄº¬Òå
·´Ð±¸Ü±¾ÉíÐèҪʹÓ÷´Ð±¸ÜתÒå¡£
ÓÉÓÚÕýÔò±í´ïʽͨ³£¶¼°üº¬·´Ð±¸Ü£¬ËùÒÔÄã×îºÃʹÓÃԭʼ×Ö·û´®À´±íʾËüÃÇ¡£Ä£Ê½ÔªËØ(Èç r'\t'£¬µÈ¼ÛÓÚ'\\t')Æ¥ÅäÏàÓ¦µÄÌØÊâ×Ö·û¡£
ÕýÔò±í´ïʽģʽÓï·¨
ÔªËØ            º¬Òå
.               Æ¥Åä³ý»»ÐÐÍâµÄÈÎÒâ×Ö·û(Èç¹û DOTALL ÔòÁ¬»»ÐÐҲƥÅä)
^               Æ¥Åä×Ö·û´®¿ªÊ¼(Èç¹ûMULTILINE£¬Ò²Æ¥Åä»»ÐзûÖ®ºó)
$               Æ¥Åä×Ö·û´®½áÊø(Èç¹ûMULTILINE£¬Ò²Æ¥Åä»»Ðзû֮ǰ)
*               Æ¥Åä0¸ö»ò¸ü¶à¸öÓÉÇ°ÃæµÄÕýÔò±í´ïʽ¶¨ÒåµÄƬ¶Î£¬Ì°À··½Ê½(¾¡¿ÉÄܶàµÄÆ¥Åä)
+               Æ¥Åä1¸ö»ò¸ü¶à¸öÓÉÇ°ÃæµÄÕýÔò±í´ïʽ¶¨ÒåµÄƬ¶Î£¬Ì°À··½Ê½
?              


Ïà¹ØÎĵµ£º

PythonÎļþµÄ¶Áд

Ïà±Èjava¶øÑÔ£¬PythonÓü¸ÐдúÂë¾Í¿ÉÒÔ´úÌæjavaÊ®À´ÐеĴúÂ룬ÕæµÄ·Ç³£²»´í
'''
Created on 2009-9-2
@author: jiangqh
'''
# file create and write
context = '''hello world
hello china '''
f = file("hello.txt",'w')
f.write(context)
f.close()
Îļþ´´½¨
#use readline() read file
f = o ......

¹ØÓÚPythonÖÐÒ»Öֻص÷·½Ê½µÄʵÏÖ

#¹ØÓڻص÷¹¦ÄܵIJâÊÔ
#FunctorÊÇÕâÖֻص÷¹¦ÄܵĹؼü¶ÔÏó
class Functor:
    """Simple functor class."""
    def __init__( self, fn, *args ):
        self.fn = fn
        ......

pythonÄ£¿éÖ®ConfigParser: ÓÃpython½âÎöÅäÖÃÎļþ

ÔÚ³ÌÐòÖÐʹÓÃÅäÖÃÎļþÀ´Áé»îµÄÅäÖÃһЩ²ÎÊýÊÇÒ»¼þºÜ³£¼ûµÄÊÂÇ飬ÅäÖÃÎļþµÄ½âÎö²¢²»¸´ÔÓ£¬ÔÚpythonÀï¸üÊÇÈç´Ë£¬ÔÚ¹Ù·½·¢²¼µÄ¿âÖоͰüº¬ÓÐ×öÕâ¼þÊÂÇé
µÄ¿â£¬ÄǾÍÊÇConfigParser£¬ÕâÀï¼òµ¥µÄ×öһЩ½éÉÜ¡£
   
ConfigParser½âÎöµÄÅäÖÃÎļþµÄ¸ñʽ±È½ÏÏóiniµÄÅäÖÃÎļþ¸ñʽ£¬¾ÍÊÇÎļþÖÐÓɶà¸ösection¹¹³É£ ......

python·ÃÎÊ sql server

½ñÌìÊÔÑéʹÓÃpythonÁ¬½Ó sql server ·þÎñÆ÷¡£ÎҼǵÃÒÔǰʹÓÃadoÁ¬½Óaccess·Ç³£Ë³Àû£¬µ«ÊǽñÌìʹÓÃadoÁ¬½Ósql server¾¹È»²»³É¹¦¡£ÔÚpythonÀïÃæµÄ³ö´íÐÅÏ¢¶¼ÏÔʾΪתÒÆÐòÁУ¬·ÑÁË°ëÌì¾¢²Å¸ãÃ÷°×£ºÎÞЧµÄÀà±ð×Ö·û´®¡£
ÊÇÁ¬½Ó×Ö·û´®Â𣿲âÊÔÁ˺ü¸¸ö È·ÈÏÎÞÎóµÄÊý¾Ý¿âÁ¬½Ó×Ö·û´®£¬Ò²ÊÇÈç´Ë ¡£ÉÏÍøËÑË÷£¬ÊÇÓпÉÄÜÊÇ comµÄÀà±ð×Ö ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ