python匹配ip正则 #!/usr/bin/env python # -*- coding:utf-8 -*- import re ip_str = "asdad1.1.1.1sdfwe2.6.5.7sdfsf2.3.94.5sdf200.198.25.0" res = [] for i in range(1): ip_t = True m_ind = 0 while ip_t: m = re.search(r"(((2([0-4]\d|5[0-5])|((1\d|[1-
import re u = "http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+" def match_by_re(str): pattern = re.compile(u, re.S) res = pattern.findall(string=str) if res: return res[0]
使用正则表达式匹配以 .com 或 .cn 为域名后缀的URL地址 In [1]: import re In [2]: str = "http://www.baidu.com/" In [3]: regular = re.compile(r'[a-zA-Z]+://[^\s]*[.com|.cn]') In [4]: re.findall(regular, str) Out[4]: ['http://www.baidu.com']
js验证首位必须是字母 var str = "asfg"; /^[a-zA-Z].*/.test(str);//true是,false否 匹配所有空格 var str=" ss dd ss "; str.replace(/\s+/g,'11'); console.log(str);//11ss11dd11 匹配中括号里面的东西 var str="123[你的]456[我的]789123[你的1]456[我的1]789"; var reg= /(?