>我的文件中有以下文本
autovue.bindir=C:\Program Files (x86(\AV\bin\
autovue.classpath=C:\Program Files (x86(\AV\bin\jvue.jar;C:\程序 Files (x86(\AV\bin\jvueserver.jar;C:\程序文件 (x86(\AV\bin\jsonrpc4j.jar;C:\程序文件 (x86(\AV\bin\log4j-api.jar;C:\程序文件 (x86(\AV\bin\杰克逊.jar;C:\程序文件 (x86(\AV\bin\stax2-api-4.2.jar;C:\程序文件 (x86(\AV\bin\woodstox-core-5.2.0.jar;C:\程序文件 (x86(\AV\bin\log4j-core.jar;C:\程序文件 (x86(\AV\bin\log4j-web.jar;C:\程序文件 (x86(\AV\bin\杰克逊.jar;C:\程序文件 (x86(\AV\bin\stax2-api-4.2.jar;C:\程序文件 (x86(\AV\bin\woodstox-core-5.2.0.jar;C:\程序文件 (x86(\AV\bin\jogl.jar;C:\程序文件 (x86(\AV\bin\gluegen-rt.jar;C:\程序文件 (x86(\AV\bin\SmartMarkupListener.jar autovue.jre=C:\Program Files (x86(\AV\jre\bin\java.exe
我需要获取 autovue.classpath 的值,表示 autovue.classpath="..."到空格(即(下一行。
我试过
MatchCollection matched=Regex.Matches(contents,@"classpath=s*")
&
MatchCollection matched=Regex.Matches(contents,@"classpath=[A-Za-z-0-9]w+")
但没有得到预期。
这应该是 C# 语言中的正则表达式。
预期成果:
C:\Program Files (x86(\AV\bin\jvue.jar;C:\程序文件 (x86(\AV\bin\jvueserver.jar;C:\程序文件 (x86(\AV\bin\jsonrpc4j.jar;C:\程序文件 (x86(\AV\bin\log4j-api.jar;C:\程序文件 (x86(\AV\bin\杰克逊.jar;C:\程序文件 (x86(\AV\bin\stax2-api-4.2.jar;C:\程序文件 (x86(\AV\bin\woodstox-core-5.2.0.jar;C:\程序文件 (x86(\AV\bin\log4j-core.jar;C:\程序文件 (x86(\AV\bin\log4j-web.jar;C:\程序文件 (x86(\AV\bin\杰克逊.jar;C:\程序文件 (x86(\AV\bin\stax2-api-4.2.jar;C:\程序文件 (x86(\AV\bin\woodstox-core-5.2.0.jar;C:\程序文件 (x86(\AV\bin\jogl.jar;C:\程序文件 (x86(\AV\bin\gluegen-rt.jar;C:\程序文件 (x86(\AV\bin\SmartMarkupListener.jar
Match match = Regex.Match(contents, @"(?<=autovue.classpath=)[^rn]+");
解释:
(?<=autovue.classpath=)
是对文本autovue.classpath=
的积极回顾。这不包括在比赛结果中。
然后,[^rn]+
匹配任意数量的字符(不是回车符或换行符(以包含在匹配项中。
如果您只想获取autovue.classpath
和下一个分号之间的文本(例如C:Program Files (x86)AVbinjvue.jar
,然后:
MatchCollection matched = Regex.Matches(contents, @"(?<=autovue.classpath=).+?(?=;)");
var match = Regex.Match(text, @"autovue.classpath=(.*)$", RegexOptions.Multiline);
将找到autovue.classpath=
和行尾之间的文本。您可以在以下位置访问它match.Groups[1]
.