c# - 如何检测 C++ 标识符字符串?

标签 c# .net c++

例如:

isValidCppIdentifier("_foo") // returns true
isValidCppIdentifier("9bar") // returns false
isValidCppIdentifier("var'") // returns false

我写了一些快速代码但它失败了: 我的正则表达式是 [a-zA-Z_$][a-zA-Z0-9_$]*" 我只需执行 regex.IsMatch(inputString)

谢谢..

最佳答案

它应该与一些添加的 anchor 一起工作:

"^[a-zA-Z_][a-zA-Z0-9_]*$"

如果您真的需要使用 Unicode 支持可笑的标识符,请随意阅读该标准的各种版本之一并将所有范围添加到您的正则表达式中(例如,http://www-d0.fnal.gov/~dladams/cxx_standard.pdf 的第 713 和 714 页)

关于c# - 如何检测 C++ 标识符字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3588467/

相关文章:

c# - Process.WaitForExit 不使用 __debugbreak 触发

c++ - 如何从迭代器中找到一对的类型?

c# - 从多个插件加载程序集,但只加载一次

.net - 添加我自己的 WPF TriggerAction

c++ - 我该如何修复错误 : conversion from ‘void’ to non-scalar type ‘std::vector<int>’ requested

c++ - Boost ASIO TCP计时器客户端错误 “resolve: The specified class is not found”

c# - Entity Framework 中没有显式外键的急切加载相关实体

c# - Richtextbox 行数

c# - ListBox 的 SelectionChanged 事件第二次不起作用

c# - 将字节数组发送到 WCF 服务