我希望使用正则表达式在字符串中查找已注释的行。我尝试了以下代码,但它只返回第一个
//
之后的内容。为什么会这样呢?program Project1;
uses
RegularExpressions;
var
Text: string;
Pattern: string;
RegEx: TRegEx;
Match: TMatch;
begin
Text := 'Hello' + #13#10
+ '// Test' + #13#10
+ 'Text' + #13#10;
Pattern := '//[^$]*$';
RegEx := TRegEx.Create(Pattern, [roCompiled, roMultiLine]);
Match := RegEx.Match(Text);
if (Match.Success) then
begin
Match.Index; // 8 -> Expected
Match.Length; // 15 -> I would like to have 9
end;
end.
(?m)
来告诉它在换行符处进行匹配。 - Ron Maupin