随笔分类 -  正则表达式

摘要:#encoding: utf-8 import re # 分组 text = "apple's price $99,orange's price is $10" ret = re.search('.*(\$\d+).*(\$\d+)',text) print(ret.group(0)) # ret. 阅读全文
posted @ 2020-03-13 11:34 胡辣汤王子 阅读(210) 评论(0) 推荐(0)
摘要:#encoding: utf-8 import re text = "apple price is $299" ret = re.search("\$\d+",text) print(ret.group()) # r = raw = 原生的 # text = '\n' # print(text) t 阅读全文
posted @ 2020-03-13 11:32 胡辣汤王子 阅读(397) 评论(0) 推荐(0)
摘要:import re # 1. 匹配某个字符串: text = "hello" ret = re.match('he',text) print(ret.group()) # 2. 点:匹配任意的字符 text = "\n" ret = re.match('.',text) print(ret.grou 阅读全文
posted @ 2020-03-13 11:31 胡辣汤王子 阅读(323) 评论(0) 推荐(0)