Home > Blockchain >  Regex for Ronin wallet address
Regex for Ronin wallet address

Time:02-21

I created a regex to identify the following string example:

ronin:50460c4cd74094cd591f454cad457e99c4ab8bf1

The regex doesn't recognize it. This is it:

let roninWalletPattern = #"ronin:[a-fA-F0-9]{46}"#

// Checks regex
let result = walletAddress.range(
        of: roninWalletPattern,
        options: .regularExpression
)
let validAddress = (result != nil)

so if it's nil is not valid.

What am I missing on that regex?

CodePudding user response:

There are only 40 characters after the ronin: part, not 46. The {46} only applies to the previous token, which is [a-fA-F0-9].

Change {46} to {40}.

  • Related