![](/img/trans.png)
[英]How to use REGEX in StepArgumentTransformation to find prefixed string
[英]How to use regex to find variable name beginning with @ in a string expression?
程序員希望通過正則表達式得到兩個變量day1和day2,字符串表達式中的其他變量也都以字符@
開頭。
字符串表達式的示例: @day1 - @day2 > 3
謝謝!
您可以使用 lookbehind 來獲取變量名,如下所示:
var regex = new Regex("(?<=@)\\w+");
這將得到前面帶有@符號的單詞
您可以在這里簡單地使用積極的前瞻。
string = "@day1 - @day2 > 3";
Regex regex = new Regex("(?<=@)\\w+", RegexOptions.Compiled);
var match = regex.Matches(a);
foreach( var val in match )
{
Console.WriteLine(val);
}
val 包含匹配值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.