Last active
February 9, 2023 23:12
-
-
Save ruxo/7f2cbd857742452bc74e8704e7906e55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open System | |
| open System.Text.RegularExpressions | |
| let private encodingMatch (m: Match) = | |
| match m.Value[0] with | |
| | '+' -> "-" | |
| | '/' -> "_" | |
| | _ -> m.Value | |
| let private decodingMatch (m: Match) = | |
| match m.Value[0] with | |
| | '-' -> "+" | |
| | '_' -> "/" | |
| | _ -> failwith "Impossible" | |
| let s = "hello+world/na==" | |
| let r = Regex.Replace(s.TrimEnd('='), "[+/]", encodingMatch) |> Dump // LINQPad's Dump | |
| Regex.Replace(r, "[-_]", decodingMatch) + String('=', 4 - r.Length % 4) |> Dump |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment