I am trying to get a regex to retrieve alphanumeric OTP code (length of the code maybe dynamic i.e depending on user's choice) and must contain at least one digit.
I have tried the following regex : "[a-zA-z][0-9].[a-zA-z]"
But if a special character is there in the code it should result null instead it retrieves the characters before and after the special character which is not desired.
Some sample OTP-containing messages on which the regex is desired to work successfully:
- OTP is **** for txn of INR 78.90.
- **** is your one-time password.
- Hi, Your OTP is ****.
Examples of Alphanumeric OTPs with at least one-digit:
- 78784
- aZ837
- 987Ny
- 19hd35
- fc82pl