匹配C语言数字的正则表达式
Regex expression to match C language numbers
我试图匹配Qt中的数字语法突出显示,我正在尝试以下正则表达式:
"[^a-fA-F_][0-9]+" // For numbers.
"[^a-fA-F_][0-9]+\.[0-9]+" // For decimal numbers.
"[^a-fA-F_][0-9]+\.[0-9]+e[0-9a-fA-F]+" // For scientific notation.
"[^a-fA-F_]0[xX][0-9a-fA-F]+" // For hexadecimal numbers.
但是文本匹配,例如,[1024,并突出显示[。我想只突出显示1024的部分。
另一个问题是,当我键入aoe2和aoe25时,regex突出显示。当数字前面有字母或下划线时,我不想突出显示它,因为那样它将是一个标识符。
我怎么解决这个问题?
它匹配[
,因为这个语句:
[^a-fA-F_]
This will match anything that is not the letters A-F(any case) or an underscore
如果你想要的话,为什么不直接匹配数字呢?
For integers: bd+
For decimal numbers: bd+.d+
For scientific: bd+ed+
For hexadecimal: b[dA-Fa-F]+
也正如@Jan Dvorak提到的,你可以使用单词边界b
,以确保你的匹配从单词(或数字)的开头开始。示例如下:http://regex101.com/r/kC6dK3
相关文章:
- 正则表达式以匹配数字的重复模式,后跟任何类型的分隔符?
- 查找中间两个数字的正则表达式的匹配项
- 正则表达式,包含名称 + "string" + 数字,没有其他内容
- 正则表达式匹配字符串之间的数字
- 使用正则表达式C++计算数字中的十进制空格
- C ++正则表达式允许用点分隔的数字
- 如何使用正则表达式将输入数字格式化为字符串
- 如何编写正则表达式以匹配以下数字格式?
- 正则表达式,捕获 4 个被 括起来的数字.或行开始/结束
- 如何为字符串编写正则表达式,其中包含一个数字至少一个数字,并且不包含任何字母
- 正则表达式使用数字作为标记拆分单词
- Qt 中的不匹配数字正则表达式
- C++11正则表达式:在替换字符串中捕获组后的数字
- 用于匹配字母数字的可移植正则表达式
- 正则表达式 找不到数字序列
- 正则表达式:仅限数字 + 字母数字 + 特殊字符
- 如何准备一个在匹配时转义部分数字的正则表达式
- 从字符串中提取数字(正则表达式 C++)
- 正则表达式字母数字和符号 [-*/]
- 检查输入字符串是否为数字且为C++,如果是,则将其转换为 int(正则表达式?