After receiving a MIME message, I am trying to extract the base64 encoded message from it, regardless of how many lines it spans.
The current regex pattern matches each individual line, but I want to group together multiple lines that contain matching base64 data. How can I achieve this?
var base64Regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}={2})$/gm
If there are other blocks of text within the MIME content (e.g., PGP signature), it will create separate matches for them as well, making it difficult to join all base64 matches together.
Ideally, I would like to modify the regex so that it captures everything from the first match to the next occurrence of `----------` and designates it as "match 1." Subsequent blocks of base64 data should be considered as separate matches ("match 2," etc).
To see an example of this behavior with 2 matches grouped into one, you can visit: https://regex101.com/r/32WjKa/1