3

Can anyone help me in creating a regular expression to preg_match (php) all of Cardano's public wallet address formats?

2
  • What have you tried so far? Can you share your progress? And could you give some examples of the different address formats you try to match with your regex?
    – eddex
    Aug 19 '21 at 5:21
  • Well i know there are 2 address types. The Byron which start with Ae2 and DdzFF. The second address and more recent type starts with addr1. Not sure of the min and max length of these addresses. Can't find much about it. Aug 19 '21 at 6:57
1

A regex itself isn't capable of validating if an address is valid or not. You need to have a little more logic. Probably what you're looking for is something like from_bytes/from_bech32/from_base58 utilized in this library: https://github.com/Emurgo/cardano-serialization-lib/blob/master/rust/src/address.rs

If you really need it to just be a regex, shelley addresses are pretty easy to validate in bech32 format, it's addr1[a-z0-9]+ and byron addresses are base58 encoded [1-9A-HJ-NP-Za-km-z]+. But neither of these ensure the address is accepted by the blockchain, it just loosely restricts the character set accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.