
正则表达式
zjLOVEcyj
composing code was a kind of art
展开
-
JS正则匹配先行断言和后行断言
// 只匹配出现在y后面的x 紧跟着y后面的x console.log(/(?<=y)x/.exec('acyx')); // 只匹配不是出现在y后面的x console.log(/(?<!y)x/.exec('asax')) // 只匹配出现在y前面的x console.log(/x(?=y)/.exec('xyqqa')); // 只匹配不是出现在y前面的x console.log(/x(?!y)/.exec('zsxsary')); ...原创 2022-04-19 16:52:54 · 432 阅读 · 0 评论 -
正则表达式匹配规则
匹配单个字符 匹配多个字符原创 2020-03-26 11:43:00 · 156 阅读 · 0 评论 -
正则表达式提取各种格式串
提取整数 import re s = "azx0.231xa54-*+895/5.23+56aax45as21e5wqdw2.wqd2-0.23wqd" res = re.findall(r"-?\d+", s) print(res) 提取小数 import re s = "azx0.231xa54-*+895/5.23+56aax45as21e5wqdw2.wqd2-0.23w...原创 2020-03-18 12:29:34 · 450 阅读 · 0 评论 -
python下re模块的常用方法
1.re.search(a,b)用于在字符串b中匹配正则表达式a #分组提取字符串 text = "apple 's price is $299, orange 's price is $199" res = re.search(".*(\$\d+).*(\$\d+)", text) print(res.groups()) 输出结果为 (’$299’, ‘$199’) 2.re.findal...原创 2020-02-23 18:08:22 · 274 阅读 · 0 评论 -
python下正则表达式之开始结束和或语法
1. 异或号^表示以…开始 , 若在[]中表示取反操作 import re text = "hello" res = re.search("^h", text) res1 = re.search("^e", text) print(res.group()) print(res1) 输出结果为 h None Process finished with exit code 0 2. $表示以…...原创 2020-02-23 12:09:24 · 3796 阅读 · 0 评论 -
python下re.match()方法正则表达式验证url地址
一般来说url地址前几位为 http,https或ftp 后面跟:// 再之后可出现任意非空字符 #匹配url地址 url = "https://www.baidu.com" res = re.match("(http|https|ftp)://[^\s]+", url) print(res.group()) 输出结果为 https://www.baidu.com Process fin...原创 2020-02-23 11:30:05 · 2093 阅读 · 0 评论 -
python爬虫数据解析之正则表达式及re.match()匹配多个字符方法
1. *表示匹配任意多个字符 \d*表示匹配任意多个数字字符 import re text = "123h1ello world" text1 = "123Hello world456" text2 = "hello world" res = re.match("\d*", text) res1 = re.match("\d*", text1) res2 = re.match...原创 2020-02-23 11:06:23 · 1992 阅读 · 0 评论 -
python爬虫数据解析之正则表达式及re.match()匹配单个字符方法
re.match(a,b)方法匹配字符串b是否以a开头,是的话返回a,否则返回None 1.匹配某字符串a是否以字符b开头 import re text = "hello world" res = re.match("h", text) print(res.group()) 输出结果为 h None Process finished with exit code 0 2....原创 2020-02-22 22:23:18 · 779 阅读 · 0 评论