in reply to Reliable way to detect base64 encoded strings
m{ ^ (?: [A-Za-z0-9+/]{4} )* (?: [A-Za-z0-9+/]{2} [AEIMQUYcgkosw048] = | [A-Za-z0-9+/] [AQgw] == )? \z }x
As to whether the input was the result of bas64-encoding or not, one can't tell. This sentence would be found valid up to the final period.
$ perl -MMIME::Base64 -le'print decode_base64("This sentence would be +found valid up to the final period")' | od -t x1 0000000 4e 18 ac b1 e9 ed 7a 77 1e c2 8b a5 75 b7 9f a2 0000020 e9 dd bd a9 62 76 ea 6d a2 d8 5e 7e 29 da 96 97 0000040 ab 8a 87 0a 0000044
Usually, one refers to the header associated with the content.
Update: Replaced /(?:|...|...)/ with /(?:...|...)?/
Update: Changed // to m{} to fix an unescaped / (as brought up in a reply).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reliable way to detect base64 encoded strings
by Rodster001 (Pilgrim) on Jun 29, 2009 at 22:02 UTC | |
by ikegami (Patriarch) on Jun 29, 2009 at 22:14 UTC | |
by Rodster001 (Pilgrim) on Jun 29, 2009 at 22:57 UTC | |
by hahngoldn (Initiate) on Apr 15, 2010 at 22:22 UTC | |
by ikegami (Patriarch) on Apr 16, 2010 at 05:05 UTC | |
by hahngoldn (Initiate) on Apr 16, 2010 at 22:49 UTC | |
|