首页 > 解决方案 > 有没有办法从类似数学的函数中获取参数?

问题描述

考虑以下字符串示例: x + 1 (y * 8) ^ w,z example.test

我希望能够得到:
x
y
w
z
example.test

标签: c#.net

解决方案


提取匹配正则表达式模式的子字符串:

var regex = new System.Text.RegularExpressions.Regex("[a-zA-Z_$][a-zA-Z_$\\.0-9]*");
var matches = regex.Matches("x + 1 (y * 8) ^ w,z example.test");

遍历结果MatchCollection以获取表示相关标识符的字符串。


推荐阅读