码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习笔记第十八周

时间:2017-06-24 11:16:07      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:pen   var   bsp   数组   span   div   strong   asc   dex   

目录:

  一、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学习笔记第十八周

标签:pen   var   bsp   数组   span   div   strong   asc   dex   

原文地址:http://www.cnblogs.com/xiaopi-python/p/7072600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!