VHDL 标识符的正则表达式

标签 regex vhdl

我正在尝试解析我的 VHDL 代码以进行一些额外的检查。

我正在寻找一个正则表达式来检查 VHDL 中的相关标识符。而且我对正则表达式还很陌生。

它有以下规则:

  • 只能包含字母 (A..Z a..z) 数字 (0..9) 和下划线 ('_')
  • 必须以 和 字母开头
  • 不得以下划线字符结尾
  • 不能包含两个连续的下划线字符

  • 所以我目前的问题是检查两个连续的下划线字符......

    更新:我想我只是自己回答了这个问题......请仔细检查
    [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/

    相关文章:

    javascript - 从 TitleCase、camelCase 获取最后一个词的正则表达式

    python - 重新使用与正则表达式匹配的用户输入字符串的一部分

    java - 用于搜索小写枚举常量的正则表达式

    vhdl - 为什么 `to_unsigned(0, 4) >= -1` 在运行时计算结果为 `FALSE`?

    VHDL - DE0 - QUARTUS II PLL 在 modsim 中不显示输出

    java - 正则表达式匹配特殊字符除了连字符与数字混合

    regex - Nginx:如何向 URL 添加尾部斜杠,除非它以特定名称开头

    vhdl - 简单状态机问题

    arrays - Modelsim VHDL 阵列初始化发出警告 (vcom-1320)

    VHDL 是在 Generic 中使用字符串的有效语法吗?