正则表达式_matches(Regex)
[0-9a-zA-Z.%+-] 匹配中括号中的 0-9 或者 a-z 或者 A-Z 或者 . 或者 % 或者 + 或者 -
$p = "111,222,333"
$p -match '\b\d\d\d\b'
-cmatch 匹配大小写
#通过 $matches 取返回值
'\b\d\d\d\b' = '\b[0-9][0-9][0-9]\b' = '\b\d\d\d\b'

$p = "111,222,333"
$p -match '\b\d\d\d\b' #只会返回一个匹配项
使用 [Regex]:Matches,会将对该字符串中所有的匹配部分都返回,所以要尽量写全regex
[Regex]写法一:
$p = "111,222,333"
[regex]:Matches($p,"\b\d\d\d\b")
[Regex]写法二:
$p = "111,222,333"
$regex = [regex]"\b\d\d\d\b"
$regex.Matches($p)
返回结果如下图:

$pattern = "a*"
$pattern=[regex]'\b\d\b'
$input = "abaabb"
[regex]::matches($input,$pattern) #返回所有匹配结果
[regex]::ismatch($input,$pattern) #返回 true or false
=========================================================
$name = "abc_2014-06-19.txt"
$name -cmatch '^abc_(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})\.txt'
$matches

$matches.year
$matches.day
$id="/cs/blogs/tips/archive/2014/06/12/be-aware-of-side-effects.aspx"
if ($id -cmatch '^/cs/blogs/tips/archive/(?<year>\d{4})/(?<month>\d{2})/(?<day>\d{2})/(?<name>.+)\.aspx$') {
$year = $matches['year']
$month = $matches['month']
$day = $matches['day']
$name = $matches['name']
}
$matches

参考:http://www.pstips.net/regex-describing-patterns.html
正则表达式_matches(Regex)的更多相关文章
- Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答
Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答 Boost正则表达式库regex常用search和match示例 发表回复 Boo ...
- 用正则表达式(regex)匹配多项式(polynomial)
因为作业的要求,我需要识别用户从命令行输入的多项式,并且要提取出其中的系数.指数以便用于后续计算. 曾经想过用一个数组把用户所有的输入全部存进来,然后在写逻辑判断.但想想那复杂的逻辑,头皮都发麻,这时 ...
- 正则表达式,Regex类
C#regex是正则表达式类用于string的处理,查找匹配的字符串.1,先看一个例子Regex regex=new Regex(@”OK“)://我们要在目标字符串中找到"OK" ...
- python3的正则表达式(regex)
正则表达式提供了一种紧凑的表示法,可用于表示字符串的组合,一个单独的正则表达式可以表示无限数量的字符串.常用的5种用途:分析.搜索.搜索与替代.字符串的分割.验证. (一)正则表达式语言python中 ...
- 正则表达式之Regex.Replace()用法
正则表达式替换匹配到的字符串 string txt = "AAA12345678AAAA"; //匹配到的连续数字的前4位用*替换 string m =Regex.Replace( ...
- 正则表达式之Regex.Match()用法
//匹配字符串中的连续数字 string txt = "AAA12345678AAAA"; string m = Regex.Match(txt, @"\d+" ...
- 【Unity|C#】基础篇(18)——正则表达式(Regex类)
[学习资料] <C#图解教程>:https://www.cnblogs.com/moonache/p/7687551.html 电子书下载:https://pan.baidu.com/s/ ...
- 更强大的python正则表达式模块 -- regex
python内置的正则表达库re比较弱,而且似乎在好几年里都没太大的变化. 这里介绍这个python模块regex,实现了更多方便好用的功能. 比如:\p{han} 可以匹配汉字, \p{Latin} ...
- 正则表达式之Regex.Matches()用法
//提取字符串中至少连续7位的数字 string txt = "www17736123780eeeee 7377091 ddddsssss7777777"; //找到的成功匹配的集 ...
随机推荐
- Python中通过Image的open之后,去show结果打不开bmp图片,无法正常显示图片
在windows的cmd命令行下,使用Python的PIL库打开并显示一个jpg图片: ? 1 2 3 openedImg = Image.open(saveToFile); print " ...
- 【NOIP 2012 疫情控制】***
题目描述 H 国有 n 个城市,这 n 个城市用 n-1 条双向道路相互连通构成一棵树,1 号城市是首都, 也是树中的根节点. H 国的首都爆发了一种危害性极高的传染病.当局为了控制疫情,不让疫情扩散 ...
- 2、RenderScript的计算(2013.05.07)
一.官方文档翻译: Android Renderscript计算 参考网址: http://blog.csdn.net/fireofstar/article/details/7748143 http: ...
- powerdesigner简单使用
---- 1) --- 新建流程图:新建模型,选择activity的那个就可以了. ----
- 【HDOJ】1720 A+B coming
水题. #include <stdio.h> #include <string.h> #define MAXNUM 1005 int stoi(char); int main( ...
- 查看wtmp文件内容
1./var/log/wtmp文件的作用 /var/log/wtmp也是一个二进制文件,记录每个用户的登录次数和持续时间等信息! 2.查看方法:可以用last命令输出当中内容 1 2 3 ...
- 免安装oracle驱动访问数据库
try { string connStr = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.110.110)( ...
- c#调用c++动态库的一些理解
调用c++动态库一般我们这样写 [DllImport("UCamer.dll", CallingConvention = CallingConvention.Winapi)] ...
- 转自 z55250825 的几篇关于FFT的博文(三)
题目大意:给出n个数qi,定义 Fj为 令 Ei=Fi/qi,求Ei. 其实这道题就是看到有FFT模板才觉得有必要学一下的... 所以实际上就是已经知道题解了... = ...
- [HDU 1561] The more, The Better
The more, The Better Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...