首页 > 代码库 > 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学习笔记第十八周