Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想要类似的东西:
"aaaXaaaXaaaXaaaYXaaa".Split('X');
但希望它忽略“YX”。
当然,我可以简单地循环并纠正它。但是有没有内置的方法呢?
您可以使用带有否定后视的正则表达式:
string[] result = Regex.Split(s, "(?<!Y)X");
在线查看它:ideone
有关环视的更多信息:Lookahead 和 Lookbehind 零宽度断言