Skip to main content
AllDevToolsHub
Back to all patterns

Binary Number (0b prefix)

Dates & Numbers

Matches a binary literal in the 0b... form (JS, Python, Rust).

/^0b[01]+$/i

How it works

Python, JavaScript (ES2015+), Rust, Go, and Java all support 0b binary literals. This regex matches that shape (case-insensitive for the prefix).

Test Cases

Should Match

  • 0b101
  • 0B11110000

Should NOT Match

  • 101
  • 0b
  • 0b102

Quick Summary

Matches a 0b-prefixed binary literal.