RegEx to match Bitcoin addresses?
[^OIl]
matches any character that's not O, I or l. The problems in your regex are:
- You don't have a
$
at the end, so it'd match any string beginning with a BC address. - You didn't count the first character in your
{27,34}
- that should be{26,33}
However, as mentioned in a comment, a regex is not a good way to validate a bitcoin address.
^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$
will match a string that starts with either 1
or 3
and, after that, 25 to 34 characters of either a-z, A-Z, or 0-9, excluding l
, I
, O
and 0
(not valid characters in a Bitcoin address).
^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$
bitcoin address is
- an identifier of 26-35 alphanumeric characters
- beginning with the number 1 or 3
- random digits
- uppercase
- lowercase letters
- with the exception that the uppercase letter
O
, uppercase letterI
, lowercase letterl
, and the number0
are never used to prevent visual ambiguity.
^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$
Based on the new address type Bech32