1

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
EvilJordan
  • 669
  • 7
  • 16

2 Answers2

9

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.

Community
  • 1
  • 1
Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • Thanks. I understand the regex, but I suppose my question should have been clearer and it's addressed a bit in your last sentence: When did these new address formats (Q|P) and bitcoincash: prefix come in to play? – EvilJordan Feb 20 '18 at 01:49
  • The API would simply implement custom protocol handling, which is covered in depth in [**this question**](https://stackoverflow.com/questions/11421048/android-ios-custom-uri-protocol-handling). The final component of your question regarding *when* they came into play would be a question for the [**Bitcoin StackExchange**](https://bitcoin.stackexchange.com). – Obsidian Age Feb 20 '18 at 02:09
  • 3
    I didn't get your comment "_strangely this can occur more than once_". `(bitcoincash:)?` - This means "_bitcoincash:_" is optional and may be present or may be missing, but if present it will occur only once. – Max Dec 25 '18 at 16:20
-1

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

Junaid Masood
  • 658
  • 11
  • 20