我正在使用 pcre_exec()
来编译正则表达式。
我想匹配具有数字的字符串,其中 3 位数字后跟“-”,但如果数字以一位或多位数字为前缀,则它不应匹配。 例如
345- => match and matches text => (345-)
:546- = match and matches text => (546-)
123- = match and matches text => (123-)
2355- = Should not match as 355- is prefixed with "2" digit.
我尝试了 ^([\\s|:]*)([0-7]\\d{2})-
但它不起作用。
最佳答案
使用后视断言前一个字符不是数字:
(?<!\d)([0-7]\d{2})-
关于c++ - 如何准备在匹配时转义部分数字的正则表达式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27505950/