zoukankan      html  css  js  c++  java
  • 正则表达式实现最小匹配

    正则表达式默认情况下实现的是最大化匹配,这在有些情况下是非常不愿意出现的,比如下面这段代码:

    # 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)

    下面是具体实现方法:

            string commentGrammer = @"(?i)\#.*?~";
    Regex commentRegex = new Regex(commentGrammer,RegexOptions.IgnoreCase|RegexOptions.Singleline);
    MatchCollection commentMC = commentRegex.Matches(input);
    foreach (Match match in commentMC)
    {
    int length = match.Length;
    int index = match.Index;
    richTextBox.Select(index, length);
    richTextBox.SelectionColor = Color.Green;
    }



  • 相关阅读:
    angularJS(5)
    angularJS(4)
    angularJS(3)
    AngularJS(1)
    angularJS(2)
    关于响应式布局
    PHP+JQUEY+AJAX实现分页【转】
    bootscript/javascript组件
    你必须收藏的Github技巧
    关于php的一些小知识!
  • 原文地址:https://www.cnblogs.com/scy251147/p/2254570.html
Copyright © 2011-2022 走看看