1个回答
展开全部
>>> src = ur"""
... 8.5
... """
>>> src
u'\n 8.5 \n'
>>> import re
>>> patt = re.compile(r"(\d+\.\d+)")
>>> patt.findall(src)
[u'8.5']
>>>
追答
Help on function search in module re:
search(pattern, string, flags=0)
Scan through string looking for a match to the pattern, returning
a match object, or None if no match was found.
findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.
If one or more groups are present in the pattern, return a
list of groups; this will be a list of tuples if the pattern
has more than one group.
Empty matches are included in the result.
(END)
Example:
>>> context = ur"""
... 8.5
... """
>>> context
u'\n 8.5 \n'
>>> patt = re.compile(r"(\d+\.\d+)")
>>> m = patt.search(context)
>>> m.group()
u'8.5'
>>> f = patt.findall(context)
>>> f
[u'8.5']
>>>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询