Home > Web Front-end > JS Tutorial > body text

Development experience of regular implementation of minimum matching

php中世界最好的语言
Release: 2018-03-29 17:55:36
Original
1715 people have browsed it

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;
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template