string[] num = Regex.Split(expr, @"\(|\)|\-|\+|\*|\/").Where(s => !String.IsNullOrEmpty(s)).ToArray();
为此,我得到了运算符和括号 。
Use lookaround ie lookahead and lookbehind to split the input
(?<=\(|\)|\-|\+|\*|\/)|(?=\(|\)|\-|\+|\*|\/)
^
Without lookaround the regex engine would split on those characters and eat it ie it won't show it in the result
If you want to evaluate mathematical expressions,have a look at these
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.