Python论坛  - 讨论区

标题:[python-chinese] 请教个正则匹配出错的问题

2006年03月18日 星期六 23:56

imcs ee imcsee at gmail.com
Sat Mar 18 23:56:43 HKT 2006

Õâ¸ö³ÌÐò´Óºº×ֵõ½Æ´Òô£¬½á¹û"A"¿ÉÒÔ·µ»Øshang4,"­["¾Í³ö´íÁË¡£
³ö´íÐÅÏ¢ÊÇ sre_constants.error: unbalanced parenthesis
ÄÄλ֪µÀÊÇʲôԭÒòÄØ¡£
--
#!/usr/bin/python
# -*- coding: cp936 -*-
data = """Ashang4
­[fan2
­\jin1
"""
import re
strIn = 'A'
pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", data, re.M)
if pos==None: print  strIn
else: print  pos.group(1)
strIn = '­['
pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", data, re.M)
if pos==None: print  strIn
else: print  pos.group(1)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060318/5a81309b/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月19日 星期日 02:06

imcs ee imcsee at gmail.com
Sun Mar 19 02:06:37 HKT 2006

ÎÊÁËˮľ£¬ÓÐλÐǪ̈˵ÊÇÖÐÎıàÂëµÄÎÊÌ⣬ת»»Ê§°ÜµÄ×ÖÀïÃæÓиö×óÖÐÀ¨ºÅ...
>>> '­['
'\xad['
>>>


On 3/18/06, imcs ee <imcsee at gmail.com> wrote:
>
>  Õâ¸ö³ÌÐò´Óºº×ֵõ½Æ´Òô£¬½á¹û"A"¿ÉÒÔ·µ»Øshang4,"­["¾Í³ö´íÁË¡£
> ³ö´íÐÅÏ¢ÊÇ sre_constants.error: unbalanced parenthesis
> ÄÄλ֪µÀÊÇʲôԭÒòÄØ¡£
> --
> #!/usr/bin/python
> # -*- coding: cp936 -*-
> data = """Ashang4
> ­[fan2
> ­\jin1
> """
> import re
> strIn = 'A'
> pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", data, re.M)
> if pos==None: print  strIn
> else: print  pos.group(1)
> strIn = '­['
> pos=re.search("^"+strIn+"([0-9a-zA-Z]+)", data, re.M)
> if pos==None: print  strIn
> else: print  pos.group(1)
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060319/384f8466/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月19日 星期日 08:11

makeyunbad makeyunbad at gmail.com
Sun Mar 19 08:11:28 HKT 2006

1NogMDYtMy0xOaOsaW1jcyBlZTxpbWNzZWVAZ21haWwuY29tPiDQtLXAo7oKPiDOysHLy67EvqOs
09DOu9DWzKjLtcrH1tDOxLHgwuu1xM7KzOKjrNequ7vKp7DctcTX1sDvw+bT0Lj21/PW0MCousUu
Li4KPiA+Pj4gJ61bJwo+ICdceGFkWycKPiA+Pj4KCsrH1eLR+bChCgo+Pj4gYSA9ICetWycKPj4+
IHJlLnNlYXJjaCgnXHhhZFsnLGEpClRyYWNlYmFjayAobW9zdCByZWNlbnQgY2FsbCBsYXN0KToK
ICBGaWxlICI8aW50ZXJhY3RpdmUgaW5wdXQ+IiwgbGluZSAxLCBpbiA/CiAgRmlsZSAiQzpcUHl0
aG9uMjRcbGliXHNyZS5weSIsIGxpbmUgMTM0LCBpbiBzZWFyY2gKICAgIHJldHVybiBfY29tcGls
ZShwYXR0ZXJuLCBmbGFncykuc2VhcmNoKHN0cmluZykKICBGaWxlICJDOlxQeXRob24yNFxsaWJc
c3JlLnB5IiwgbGluZSAyMjcsIGluIF9jb21waWxlCiAgICByYWlzZSBlcnJvciwgdiAjIGludmFs
aWQgZXhwcmVzc2lvbgplcnJvcjogdW5leHBlY3RlZCBlbmQgb2YgcmVndWxhciBleHByZXNzaW9u
Cj4+PiByZS5zZWFyY2goJ1x4YWRcWycsYSkKPF9zcmUuU1JFX01hdGNoIG9iamVjdCBhdCAweDAx
MjlBNTk4PgoK1PXDtLSmwO3E2KOsxqXF5Naux7C2vNKqsunV0tDeuMTX1rf7tK7DtKO/Cg==

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2006年03月19日 星期日 11:22

Shixin Zeng shixinzeng at gmail.com
Sun Mar 19 11:22:43 HKT 2006

On 3/19/06, makeyunbad <makeyunbad at gmail.com> wrote:
>
> ÔÚ 06-3-19£¬imcs ee<imcsee at gmail.com> дµÀ£º
> > ÎÊÁËˮľ£¬ÓÐλÐǪ̈˵ÊÇÖÐÎıàÂëµÄÎÊÌ⣬ת»»Ê§°ÜµÄ×ÖÀïÃæÓиö×óÖÐÀ¨ºÅ...
> > >>> '­['
> > '\xad['
> > >>>
>
> ÊÇÕâÑù°¡
>
> >>> a = '­['
> >>> re.search('\xad[',a)
> Traceback (most recent call last):
>   File "", line 1, in ?
>   File "C:\Python24\lib\sre.py", line 134, in search
>     return _compile(pattern, flags).search(string)
>   File "C:\Python24\lib\sre.py", line 227, in _compile
>     raise error, v # invalid expression
> error: unexpected end of regular expression
> >>> re.search('\xad\[',a)
> <_sre.SRE_Match object at 0x0129A598>
>
> Ôõô´¦ÀíÄØ£¬Æ¥Åä֮ǰ¶¼Òª²éÕÒÐÞ¸Ä×Ö·û´®Ã´£¿


ÊÔÊÔ°ÑËüÃǶ¼×ª»¯ÎªunicodeÀ´´¦Àí¿´

_______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>


--
Best regards

Shixin Zeng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060319/ea20afda/attachment-0001.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号