博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
正则表达式
阅读量:4615 次
发布时间:2019-06-09

本文共 923 字,大约阅读时间需要 3 分钟。

1.  (x)

->   'bar foo'.replace( /(..) (...)/, '$2 $1' )

->   "bfoo ar"

2.  (x)

->   "foo bar foo bar".match(/(bar) (foo)/, '$2 $1');

->   ["bar foo", "bar", "foo"]

3.  (x)

->   "foo bar foo bar".match(/(bar) (foo)/, '$&');

->   ["bar foo", "bar", "foo"]

4. x(?!y)  Matches 'x' only if 'x' is not followed by 'y'

-> /\d+(?!\.)/.exec("3.141")

->["141"]

5.x(?=y)  Matches 'x' only if 'x' is followed by 'y'.

->   /\d+(?=\.)/.exec("3.141")

->  ["3"]

6.  {n}  

->  /a{2}/.exec("cass")

->  null
->  /a{2}/.exec("caass")
->  ["aa"]
->  /a{2}/.exec("caaaaaass")
->  ["aa"]

6. {n,m}

->  /a{2,4}/.exec("caaaaaass")

->  ["aaaa"]

7. [xyz]    Special characters like the dot(.) and asterisk (*) are not special inside a character set, so they don't need to be escaped

->  /[a-z.]+/.exec("test.i.ngaa11111")

->  ["test.i.ngaa"]

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

转载于:https://www.cnblogs.com/Sir-Lin/p/6529759.html

你可能感兴趣的文章
splay入门
查看>>
带CookieContainer进行post
查看>>
C语言学习笔记--字符串
查看>>
CSS-上下文选择器
查看>>
ionic repeat 重复最后一个时要执行某个函数
查看>>
1.初识代码审计-基础
查看>>
[Vue-rx] Stream an API using RxJS into a Vue.js Template
查看>>
解决VC几个编译问题的方法——好用
查看>>
SPOJ #11 Factorial
查看>>
City Upgrades
查看>>
“人少也能办大事”---K2 BPM老客户交流会
查看>>
关于七牛进行图片添加文字水印操作小计
查看>>
DataSource数据库的使用
查看>>
Luogu4069 SDOI2016 游戏 树链剖分、李超线段树
查看>>
Java的内部类真的那么难以理解?
查看>>
一文搞懂Java环境,轻松实现Hello World!
查看>>
hash实现锚点平滑滚动定位
查看>>
也谈智能手机游戏开发中的分辨率自适应问题
查看>>
关于 IOS 发布的点点滴滴记录(一)
查看>>
《EMCAScript6入门》读书笔记——14.Promise对象
查看>>