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.
在输入 AutoCompleteTextBox 期间如何提供@提及列表?
我提到的模式是这样的:
String pattern = "@[a-zA-Z0-9_.]+?(?![a-zA-Z0-9_.])";
示例:考虑用户尝试输入两个提及,甚至尝试编辑其中一个,文本如下:
谢谢@marvel308 和@Dav 回答我的问题
您可以简化您的正则表达式。试试这个代码:
var input = "Thank you @marvel308 and @Dav for answering my question"; var regex = new Regex("@(?<name>[^\\s]+)"); var results = regex.Matches(input) .Cast<Match>() .Select(m => m.Groups["name"].Value) .ToArray();