“Base-encoded data” is one of the patterns that you can select on the Match panel. Use this pattern to match specific bytes or text encoded as base64, base32, or base16. You can also use this pattern to match a certain number of bytes encoded as base64, base32, or base16.
This example shows how you can use the “base-encoded data” pattern to make your regular expression match certain bytes encoded as base64. You can find this example as “Pattern: base-encoded data” in the RegexMagic library.
UmVnZXhNYWdpYw UmVnZXhNYWdpYw== UmVnZXhNYWdpYyByb2Nrcw== UmVnZXhNYWdpYyByb2NrcyE=
button to add field
.
UmVnZXhNYWdpYw(?:={2})?Required options: Case sensitive.
UmVnZXhNYWdpYw UmVnZXhNYWdpYw== UmVnZXhNYWdpYyByb2Nrcw== UmVnZXhNYWdpYyByb2NrcyE=
As demonstrated by this example, the key feature of the “base-encoded data” pattern is that you provide RegexMagic with the underlying text or bytes that you’re trying to search for, which RegexMagic then converts to base64, base32, or base16. In this example we provide “RegexMagic” as the text to match. RegexMagic first determines the bytes that represent the text in our chosen encoding (UTF-8). It then converts those bytes to base64, which in this case produces “UmVnZXhNYWdpYw”. The generated pattern then matches this text. If you already have the base64 representation of the data you’re looking for then you can use the “literal text” instead.
Note that base64 uses blocks of 4 characters to encode blocks of 3 bytes. If the text you want to match is not a multiple of 3 bytes then the missing bytes affect the encoding. In the sample text above, the first two lines encode “RegexMagic” without and with padding. The 3rd line encodes “RegexMagic rocks” and the 4th “RegexMagic rocks!”. Our regex does not match the 3rd and 4th lines even though they encode “RegexMagic” because “c” is encoded as “Yw” while “c r” is encoded as “YyBy”. If you want to search for shorter strings within longer base64 data you need to take this into account. We can modify the above example to make it match the start of all 4 lines:
UmVnZXhNYWdpRequired options: Case sensitive.
UmVnZXhNYWdpYw UmVnZXhNYWdpYw== UmVnZXhNYWdpYyByb2Nrcw== UmVnZXhNYWdpYyByb2NrcyE=