in reply to Re^2: Reliable way to detect base64 encoded strings
in thread Reliable way to detect base64 encoded strings

It's actually really straightforward.

It's probably a bit simpler after the update I just did for you:

Replies are listed 'Best First'.
Re^4: Reliable way to detect base64 encoded strings
by Rodster001 (Pilgrim) on Jun 29, 2009 at 22:57 UTC
    Your explanation makes it very clear... thanks again!
Re^4: Reliable way to detect base64 encoded strings
by hahngoldn (Initiate) on Apr 15, 2010 at 22:22 UTC

    Regex are not my favorite part of Perl....even if they are powerful. I'm trying to use your way to detect if a string is base64...so I was taking what you had and putting an if around it. I'm sure I'm just not getting it....could you give me some pointers?

    if($string_whole =~ m / ^ (?: [A-Za-z0-9+/]{4} )* (?: [A-Za-z0-9+/]{2} [AEIMQUYcgkosw048] = | [A-Za-z0-9+/] [AQgw] == )? \z /x ) $&Log ("it found base64-$i");
    Thanks in advance for your expertise.

      You have the right idea, but

      if (...) $&Log ("it found base64-$i");
      is not valid Perl. You want
      if($string_whole =~ m/ ^ (?: [A-Za-z0-9+/]{4} )* (?: [A-Za-z0-9+/]{2} [AEIMQUYcgkosw048] = | [A-Za-z0-9+/] [AQgw] == )? \z /x) { Log("$string_whole is valid base64"); }
        when I use it as you have it I get
        Unmatched [ in regex; marked by <-- HERE in m/ ^ (?: [ <-- HERE A-Za-z0-9+/ at C:\aaa\aeh_pop.pl line 153.
        I thought I was getting a problem with the regex...not the IF....but I didn't copy this in because i figured it was something I was doing. I see matched brackets... I tried to pull up into one line thinking the white space was giving issues...that didn't help. Thanks.