Regular Expressions 101

Community Patterns

Parse OTP from QR Code

1

Regular Expression
ECMAScript (JavaScript)

/
otpauth:\/\/([ht]otp)\/(?:[a-zA-Z0-9%]+:)?([^\?]+)\?secret=([0-9A-Za-z]+)(?:.*(?:<?counter=)([0-9]+))?
/
g

Description

This regular expression parses the uri of an one-time password typically masked by a QR Code.

The expression supports the core hotp and totp, name, secret and optional counter (for hotp)

Submitted by Carsten and Craig - 8 years ago