Home >Web Front-end >JS Tutorial >Development experience of regular implementation of minimum matching
This time I will bring you the development experience of regular implementation of minimum matching. What are the precautions for regular implementation of minimum matching. The following is a practical case, let's take a look.
The example of this article describes the method of regular expression to achieve the minimum matching function. Share it with everyone for your reference, as follows:
Regular expressions achieve maximum matching by default, which is very undesirable in some cases, such as the following code:
# 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~
We want to match any text between # and ~. The way to achieve the minimum match is to use (?i)
The following is the specific implementation method:
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; }
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Detailed explanation of using regular expressions to extract strings (with code)
How to use regular expressions to find letters and numbers in js
The above is the detailed content of Development experience of regular implementation of minimum matching. For more information, please follow other related articles on the PHP Chinese website!