RegEx for detecting base64 encoded strings

后端 未结 3 1836
北荒
北荒 2021-02-07 16:26

I need to detect strings with the form @base64 (e.g. @VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==) in my application.

The @ has to be at the begin

3条回答
  •  情歌与酒
    2021-02-07 17:21

    Here's an alternative regular expression:

    ^@(?=(.{4})*$)[A-Za-z0-9+/]*={0,2}$
    

    It satisfies the following conditions:

    • The string length after the @ sign must be a multiple of four - (?=^(.{4})*$)
    • The content must be alphanumeric characters or + or / - [A-Za-z0-9+/]*
    • It can have up to two padding (=) characters on the end - ={0,2}

提交回复
热议问题