Numbersflags: g
Binary Number Literal
Match binary number literals like `0b1010` or `0B11110000`.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
\b0[bB][01]+\b (flags: g)Raw source: \b0[bB][01]+\b
How it works
\b is a word boundary so we don't match inside identifiers. 0[bB] matches the literal prefix (case-insensitive on the b). [01]+ matches one or more binary digits. Trailing \b prevents matching into adjacent word characters.
Examples
Input
Mask = 0b1010, halfbyte = 0B1111Matches
0b10100B1111
Input
for i := 0; i < 0b1000; i++Matches
0b1000
Input
no binary hereNo match
—Common use cases
- •Source-code analysis for bitmask literals
- •Embedded / firmware tooling
- •Educational / tutorial parsing
- •Linting rules for magic numbers
Related patterns
Hexadecimal Number Literal
NumbersMatch hexadecimal number literals like `0xFF`, `0x1A2B`, or `0XdeadBeef`.
Octal Number Literal
NumbersMatch modern ECMAScript-style octal literals (`0o755`) — strict per ES6+ syntax.
Decimal Number
NumbersMatches decimal numbers, including integers and negatives.
Float / Scientific Number
NumbersMatch floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.