天天看点

Python 正则表达式验证带分隔符的数字

1. Find any decimal or octal integer with optional underscores in a larger body of text
\b[0-9]+(_+[0-9]+)*\b

2. Find any hexadecimal integer with optional underscores in a larger body of text
\b0[xX][0-9a-fA-F]+(_+[0-9a-fA-F]+)*\b

3. Find any binary integer with optional underscores in a larger body of text
\b0[bB][01]+(_+[01]+)*\b

4. Find any decimal, octal, hexadecimal, or binary integer with optional underscores in a larger body of text
\b([0-9]+(_+[0-9]+)*|0[xX][0-9a-fA-F]+(_+[0-9a-fA-F]+)*|0[bB][01]+(_+[01]+)*)\b
           

继续阅读