Pattern: Bitcoin address

“Bitcoin address” is one of the patterns that you can select on the Match panel. Use this pattern to make a field match a Bitcoin address. You can select which types of Bitcoin addresses the pattern should allow.

This example shows how you can use the “Bitcoin address” pattern to look for Bitcoin addresses. You can find this example as “Pattern: Bitcoin address” in the RegexMagic library.

  1. Click the New Formula button on the top toolbar to clear out all settings on the Samples, Match, and Action panels.
  2. On the Samples panel, paste in one new sample:
    11111111111111111111BZbvjr
    1111111111111111111114oLvT2
    12higDjoCCNXSA95xZMWUdPvXNmkAduhWv
    1QLbz7JHiBTspS962RLKV8GndWFwi5j6Qr
    342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey
    bc1q34aq5drpuwy3wgl9lhup9892qp6svr8ldzyy7c
    bc1qeklep85ntjz4605drds6aww9u0qr46qzrv5xswd35uhjuj8ahfcqgf6hak
    bc1pxwww0ct9ue7e8tdnlmug5m2tamfn7q06sahstg39ys4c9f3340qqxrdu9k
    BC1Q34AQ5DRPUWY3WGL9LHUP9892QP6SVR8LDZYY7C
    BC1QEKLEP85NTJZ4605DRDS6AWW9U0QR46QZRV5XSWD35UHJUJ8AHFCQGF6HAK
    BC1PXWWW0CT9UE7E8TDNLMUG5M2TAMFN7Q06SAHSTG39YS4C9F3340QQXRDU9K
    Bc1q34Aq5DrPuWy3Wgl9LhUp9892Qp6Svr8LdZyy7c
    Bc1QeKlEp85NtJz4605DrDs6Aww9u0Qr46QzRv5XsWd35UhJuj8AhFcQgf6Hak
    Bc1PxWww0Ct9Ue7e8TdNlMug5m2TaMfn7q06SaHsTg39Ys4c9f3340QqXrDu9k
    bc1p567890l234567890l234567890l234567890l234567890l234567890l2
    
  3. Select the 8th line in the sample which starts with bc1p.
  4. Click the Mark button.
  5. On the Match panel, set “begin regex match at” to “start of word”, and set “end regex match at” to “end of word”.
  6. Observe that RegexMagic has automatically detected the “Bitcoin address” pattern with the P2TR address format that we marked.



  7. Set the “field validation mode” to “average”.
  8. On the Regex panel, select “Python 3.13” as your application, turn off free-spacing, and turn off mode modifiers. Click the Generate button, and you’ll get this regular expression:
    \bbc1p[02-9ac-hj-np-z]{58}\b
    Required options: Case sensitive.
    Unused options: Exact spacing; Dot doesn’t match line breaks; ^$ don’t match at line breaks.
  9. The Samples panel now highlights the bitcoin addresses our regex matches:
    11111111111111111111BZbvjr
    1111111111111111111114oLvT2
    12higDjoCCNXSA95xZMWUdPvXNmkAduhWv
    1QLbz7JHiBTspS962RLKV8GndWFwi5j6Qr
    342ftSRCvFHfCeFFBuz4xwbeqnDw6BGUey
    bc1q34aq5drpuwy3wgl9lhup9892qp6svr8ldzyy7c
    bc1qeklep85ntjz4605drds6aww9u0qr46qzrv5xswd35uhjuj8ahfcqgf6hak
    bc1pxwww0ct9ue7e8tdnlmug5m2tamfn7q06sahstg39ys4c9f3340qqxrdu9k
    BC1Q34AQ5DRPUWY3WGL9LHUP9892QP6SVR8LDZYY7C
    BC1QEKLEP85NTJZ4605DRDS6AWW9U0QR46QZRV5XSWD35UHJUJ8AHFCQGF6HAK
    BC1PXWWW0CT9UE7E8TDNLMUG5M2TAMFN7Q06SAHSTG39YS4C9F3340QQXRDU9K
    Bc1q34Aq5DrPuWy3Wgl9LhUp9892Qp6Svr8LdZyy7c
    Bc1QeKlEp85NtJz4605DrDs6Aww9u0Qr46QzRv5XsWd35UhJuj8AhFcQgf6Hak
    Bc1PxWww0Ct9Ue7e8TdNlMug5m2TaMfn7q06SaHsTg39Ys4c9f3340QqXrDu9k
    bc1p567890l234567890l234567890l234567890l234567890l234567890l2
    

If you want to use this pattern to verify that a string is a valid Bitcoin address then set “begin/end regex match at” to “start/end of text”.

Reference