我正在尝试解析我的 VHDL 代码以进行一些额外的检查。
我正在寻找一个正则表达式来检查 VHDL 中的相关标识符。而且我对正则表达式还很陌生。
它有以下规则:
所以我目前的问题是检查两个连续的下划线字符......
更新:我想我只是自己回答了这个问题......请仔细检查
[A-Za-z](_?[A-Za-z0-9])*
最佳答案
(?!.*__)[a-zA-Z][\w]*[^_]
这应该可以解决问题。
说明:
# (?!.*__)[a-zA-Z][\w]*[^_]
#
# Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!.*__)»
# Match any single character that is not a line break character «.*»
# Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
# Match the characters “__” literally «__»
# Match a single character present in the list below «[a-zA-Z]»
# A character in the range between “a” and “z” «a-z»
# A character in the range between “A” and “Z” «A-Z»
# Match a single character that is a “word character” (letters, digits, etc.) «[\w]*»
# Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
# Match any character that is NOT a “_” «[^_]»
关于VHDL 标识符的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7959587/