What does the new BCH regex mean?

2.6k Views Asked by At

BCH regex was recently updated (in the API) to: "address_regex": "^([13][a-km-zA-HJ-NP-Z1-9]{25,34})|^((bitcoincash:)?(q|p)[a-z0-9]{41})|^((BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$"

Is this a Segwit thing?

I understand it's now saying addresses may start with "bitcoincash:" or "BITCOINCASH:", but that's a thing, or is it some internal Coinbase designation?

2

There are 2 best solutions below

3
Obsidian Age On

Breaking down this regex, there are three possible that constitute a valid BCH address:

1st Alternative ^([13][a-km-zA-HJ-NP-Z1-9]{25,34}):

  • Starts with either a 1 or a 3
  • Follows this with between 25 and 34 alphanumeric characters excluding l, I, O and 0

2nd Alternative ^((bitcoincash:)?(q|p)[a-z0-9]{41}):

  • Starts with the literal string bitcoincash: (strangely this can occur more than once)
  • Follows this with either a q or a p
  • Follows this with exactly 41 alphanumeric characters (only in lowercase)

3rd Alternative ^((BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$:

  • Starts with the literal string BITCOINCASH: (strangely this can occur more than once)
  • Follows this with either a Q or a P
  • Follows this with exactly 41 alphanumeric characters (only in uppercase)

Essentially, Coinbase is now simply accepting the three above regexes as valid BCH addresses, adding bitcoincash as a recognised protocol used by BCH.

0
Junaid Masood On

let me break it down for you so there are three regex in it, as after new additions now all three are accepted as valid BCH addresses now

/^([13]{1}[a-km-zA-HJ-NP-Z1-9]{33}|(bitcoincash:)?(q|p)[a-z0-9]{41}|(BITCOINCASH:)?(Q|P)[A-Z0-9]{41})$/

Breaking it down

First type of addresses

[13]{1}

address will start with L, M or 3, {1} defines that only match one character in square bracket

/[13]{1}[a-km-zA-HJ-NP-Z1-9]/

cannot have l (small el), I (capital eye), O (capital O) and 0 (zero)

/[13]{1}[a-km-zA-HJ-NP-Z1-9]{26,33}/

can be 27 to 34 characters long, remember we already checked the first character to be 1 or 3, so remaining address will be 26 to 33 characters long

second type of address

bitcoincash:

will start with bitcoincash:

(bitcoincash:)?(q|p)

followed by q or p

(bitcoincash:)?(q|p)[a-z0-9]

can only have lower case letters and numbers

(bitcoincash:)?(q|p)[a-z0-9]{41}

will be 54 characters long, we already checked first 11 characters to be bitcoincash: followed by another character to be Q or p, so remaining address will be 41 characters long

third type of address

BITCOINCASH:

will start with BITCOINCASH:

(BITCOINCASH:)?(Q|P)

followed by Q or P

(BITCOINCASH:)?(Q|P)[a-z0-9]

can only have lower case letters and numbers

(BITCOINCASH:)?(Q|P)[a-z0-9]{41}

will be 54 characters long, we already checked first 11 characters to be BITCOINCASH: followed by another character to be Q or P, so remaining address will be 41 characters long