对于正整数,请使用
r"(?<![-.])b[0-9]+b(?!.[0-9])"
说明:
(?<![-.]) # Assert that the previous character isn't a minus sign or a dot.b # Anchor the match to the start of a number.[0-9]+ # Match a number.b # Anchor the match to the end of the number.(?!.[0-9]) # Assert that no decimal part follows.
对于有符号/无符号整数,请使用
r"[+-]?(?<!.)b[0-9]+b(?!.[0-9])"
单词边界
b对于确保整个数字匹配至关重要。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)