I need to detect strings with the form @base64 (e.g. @VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==
) in my application.
The @ has to be at the beginning and the charset for base64 encoded strings is a-z
, A-Z
, 0-9
, +
, /
and =
. Would be the appropiate regular expresion to detect them?
Thanks
try with:
=> RegEx to parse or validate Base64 data
Something like this should do (does not check for proper length!):
The length of any base64 encoded string must be a multiple of 4, hence the additional.
See here for a solution that checks against proper length: RegEx to parse or validate Base64 data
A quick explanation of the regex from the linked answer: