最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
正则表达式实现最小匹配功能的方法
时间:2017-04-05 编辑:简简单单 来源:一聚教程网
正则表达式默认情况下实现的是最大化匹配,这在有些情况下是非常不愿意出现的,比如下面这段代码:
# starting IndiaInventoryAPP.exe" ~~DisplayVariableValues "parameterGroup,mailRecipients,ModuleArgs"~DisplayVariableValues "LogFolder"~$binaryExitCode = 0~~$IndiaInventoryArgs = "-asWin32Console -S HKDRMSUAT3 -D $DatabaseName -U $DatabaseUserName -P $DatabasePassword -L $LogFolder -MailRecipients $mailRecipients -T $today_yyyy -Z D:\cs48516\posIds.txt"~ExecuteBinaryCommand ([ref]$binaryExitCode) "$applicationPath/IndiaInventoryAPP.exe" $IndiaInventoryArgs $true~
我们想匹配#与~中间的任何文字,实现最小匹配的方法就是利用(?i)
下面是具体实现方法:
代码如下 | 复制代码 |
stringcommentGrammer =@"(?i)\#.*?~"; Regex commentRegex =newRegex(commentGrammer,RegexOptions.IgnoreCase|RegexOptions.Singleline); MatchCollection commentMC = commentRegex.Matches(input); foreach(Match matchincommentMC) { intlength = match.Length; intindex = match.Index; richTextBox.Select(index, length); richTextBox.SelectionColor = Color.Green; } |
-
上一个: Java中 和 区别
相关文章
- 匹配ul与ul之间的指定内容正则表达式 08-31
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24