Once whitespace is removed from the input, the following regex pattern will tell you whether the input is a valid base64-encoded string.
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).


In reply to Re: Reliable way to detect base64 encoded strings by ikegami
in thread Reliable way to detect base64 encoded strings by Rodster001

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.