The following regular expressions are crafted to match some commonly used cryptocurrency wallet address types. This document details the Regex components and pattern tests to match Ethereum, Bitcoin, Dash and Monero addresses.
/^0x[a-fA-F0-9]{40}$/g
/^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/g
/X[1-9A-HJ-NP-Za-km-z]{33}$/g
/4[0-9AB][1-9A-HJ-NP-Za-km-z]{93}$/g
/
Open. Indicates the start of a regular expression.
^
Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
$
End. Matches the end of the string, or the end of a line if the multiline flag (m) is enabled.
/
Close. Second "/" indicates the end of a regular expression and the start of expression flags.
{40}
Ethereum (ETH): Match 40 of the preceeding token.
{25,39}
Bitcoin (BTC): Match between 25 and 39 of the preceeding token.
{33}
Dash (DASH): Match between 33 of the preceeding token.
{93}
Monero (XMR): Match between 93 of the preceeding token.
|
Bitcoin (BTC): Alternation acts like a boolean OR. Matches the expression before or after the "|".
0
Character. Matches a "0" character (char code 48).
x
Character. Matches a "x" character (char code 120). Case sensitive.
[a-fA-F0-9]
Character Set. Match any character in the set. a-f Range matches a character in the range "a" to "f" (char code 97 to 102). Case sensitive. A-F Range matches a character in the range "A" to "F" (char code 65 to 70). Case sensitive. 0-9 matches a character in the range of "0" to "9" (char code 48 to 57). Case sensitive.
[a-zA-HJ-NP-Z0-9]
Character set. Match any character in the set. a-z Range matches a character in the range "a" to "z" (char code 97 to 122). Case sensitive. A-H Range matches a character in the range "A" to "H" (char code 65 to 72). Case sensitive. J-N Range matches a character in the range "J" to "N" (char code 74 to 78). Case sensitive. P-Z Range matches a character in the range "P" to "Z" (char code 80 to 90). Case sensitive. 0-9 Range matches a character in the range "0" to "9" (char code 48 to 57). Case sensitive.
X
Character. Matches a "X" character (char code 88). Case sensitive.
[1-9A-HJ-NP-Za-km-z]
Character set. Match hany character in the set. 1-9 Range matches a character in the range "1" to "9" (char code 49 to 57) Case sensitive. A-H Range matches a character in the range "A" to "H" (char code 65 to 72). J-N Range matches a character in the range "J" to "N" (char code 74 to 78). P-Z Range matches a character in the range "P" to "Z" (char code 80 to 90). Case sensitive. a-k Range matches a character in the range "a" to "k" (char code 97 to 107). Case sensitive. m-z Range matches a character in the range "m" to "z" (char code 109 to 122). Case sensitive.
4
Character. Matches a "4" character (char code 52).
[0-9AB]
Character set. Match any character in the set. 0-9 Range matches a character in the range "0" to "9" (char code 48 to 57). Case sensitive. A Character matches "A" character (char code 65). Case sensitive. B Character matches a "B" character (char code 66). Case sensitive.
[1-9A-HJ-NP-Za-km-z]
Character set. Match any character in the set. 1-9 Range matches a character in the range "1" to "9" (char code 49 to 57) Case sensitive. A-H Range matches a character in the range "A" to "H" (char code 65 to 72). Case sensitive. J-N Range matches a character in the range "J" to "N" (char code 74 to 78). Case sensitive. P-Z Range matches a character in the range "P" to "Z" (char code 80 to 90). Case sensitive. a-k Range matches a character in the range "a" to "k" (char code 97 to 107). Case sensitive. m-z Range matches a character in the range "m" to "z" (char code 109 to 122). Case sensitive.
g
Global search. Retain the index of the last match, allowing subsequent searches to start from the end of the previous match. Without the global flag, subsequent searches will return the same match.
(bc1|[13])
Bitcoin (BTC): Capturing Group. Groups multiple tokens together and creates a capture group for extracting a substring or using a backreference. b Character matches a "b" character (char code 98). Case sensitive. c Character matches a "c" character (char code 99). Case sensitive. 1 Character matches a "1" character (char code 49). | Alternation acts like a boolean OR. Matches the expression before or after the "|". Character set Matches any character in the set; 1 character matches a "1" character (char code 49), 3 character matches a "3" character (char code 51).
I'm Matt Brassey - Full stack developer with a focus on decentralized applications. Visit my GitHub!
lol