如何在c#中检测所有以'%'或'$'开头的字符串?
编辑:
如果我有以下字符串例如:
string test = "Shipments will cost $150USD , which representes a rise of %34 ."
如何使用regex检测$150USD
和%34
?
如果您要查找所有单词,则可以使用该正则表达式。
(?<=\s?)[%$]\w+(?=\s?)
因此,Shipments will cost $150USD, which representes a rise of %34.
它将在其中找到$150USD
和%34
。
C#代码为:
String subjectString = "Shipments will cost $150USD, which representes a rise of %34.";
var matches = Regex.Matches(subjectString, @"(?<=\s?)[%$]\w+(?=\s?)");
foreach (Match match in matches)
{
var value = match.Value;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句