首页 > 代码库 > Python学习笔记第十八周
Python学习笔记第十八周
目录:
一、JavaScript正则表达式
内容:
一、JavaScript正则表达式
1、test
判断字符串是否符合规定的正则表达式
例子:
rep = /^\d+$/
rep.test(‘123‘)返回true
2、exec
获取匹配的数据,在匹配时,默认只能匹配到第一个即返回,且匹配值以数组形式存在
例子:分组匹配,会匹配两次,第一次匹配整体,第二次会将分组内容单独匹配出来
test = ‘JavaScript is more fun than Java or JavaBeans!‘ "JavaScript is more fun than Java or JavaBeans!" var pattern = /\bJava\w*\b/ undefined pattern.exec(test) 输出:["JavaScript", index: 0, input: "JavaScript is more fun than Java or JavaBeans!"] var pattern = /\bJava(\w*)\b/ pattern.exec(test) 输出:(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!"]
例子2:全局匹配 在匹配模板后面加g
test = ‘JavaScript is more fun than Java or JavaBeans!‘ "JavaScript is more fun than Java or JavaBeans!" var pattern = /\bJava\w*\b/g undefined pattern.exec(test) ["JavaScript", index: 0, input: "JavaScript is more fun than Java or JavaBeans!"] pattern.exec(test) ["Java", index: 28, input: "JavaScript is more fun than Java or JavaBeans!"] pattern.exec(test) ["JavaBeans", index: 36, input: "JavaScript is more fun than Java or JavaBeans!"]
var pattern = /\bJava(\w*)\b/g undefined test = ‘JavaScript is more fun than Java or JavaBeans!‘ "JavaScript is more fun than Java or JavaBeans!" pattern.exec(test) (2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!"] pattern.exec(test) (2) ["Java", "", index: 28, input: "JavaScript is more fun than Java or JavaBeans!"] pattern.exec(test) (2) ["JavaBeans", "Beans", index: 36, input: "JavaScript is more fun than Java or JavaBeans!"]
二、BootStrap
- CSS
- JS
Python学习笔记第十八周
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。