前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >正则表达式中 ? 符号的一些用法

正则表达式中 ? 符号的一些用法

作者头像
老白
发布2018-03-19 16:10:19
1K0
发布2018-03-19 16:10:19
举报
文章被收录于专栏:架构之路架构之路

1.

如\d?,代表出现0个或1个数字

2.

如\d+?,代表最小贪婪,满足\d+的最小匹配,也就是只出现一个数字最好

3.

(?<name> expression) 命名的捕获组

4.

(?: expression),匹配该捕获组的内容,但是不保存该组

5.

(?<=Expression) 逆序肯定环视,表示所在位置左侧能够匹配Expression

(?<!Expression) 逆序否定环视,表示所在位置左侧不能匹配Expression

(?=Expression) 顺序肯定环视,表示所在位置右侧能够匹配Expression

(?!Expression) 顺序否定环视,表示所在位置右侧不能匹配Expression

6.

(?imsx-imsx:pattern) 其中imsx-imsx是标志修饰符

m Treat string as multiple lines. That is, change "^" and "$" from matching the start or end of the string to matching the start or end of any line anywhere within the string.

s Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match. Used together, as /ms, they let the "." match any character whatsoever, while still allowing "^" and "$" to match, respectively, just after and just before newlines within the string.

i Do case-insensitive pattern matching. If use locale is in effect, the case map is taken from the current locale. See perllocale.

x Extend your pattern's legibility by permitting whitespace and comments.

p Preserve the string matched such that ${^PREMATCH}, ${^MATCH}, and ${^POSTMATCH} are available for use after matching.

g and c Global matching, and keep the Current position after failed matching. Unlike i, m, s and x, these two flags affect the way the regex is used rather than the regex itself. See "Using regular expressions in Perl" in perlretut for further explanation of the g and c modifiers.

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-02-28 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档