正则表达式实现最小匹配功能的方法
本文实例讲述了正则表达式实现最小匹配功能的方法。分享给大家供大家参考,具体如下:
正则表达式默认情况下实现的是最大化匹配,这在有些情况下是非常不愿意出现的,比如狼蚁网站SEO优化这段代码:
# 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)
狼蚁网站SEO优化是具体实现方法:
string mentGrammer = @"(?i)\#.*?~"; Regex mentRegex = new Regex(mentGrammer,RegexOptions.IgnoreCase|RegexOptions.Singleline); MatchCollection mentMC = mentRegex.Matches(input); foreach (Match match in mentMC) { int length = match.Length; int index = match.Index; richTextBox.Select(index, length); richTextBox.SelectionColor = Color.Green; }
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
正则表达式在线生成工具:
希望本文所述对大家正则表达式学习有所帮助。
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程