How to extract a string from Base64

I am trying to extract a mime type from a Base64 string… Regex is giving me a nose bleed.

Here’s how it looks:
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O

I’d like to extract the image/jpeg which can, of course be different mime types…

So it makes sense to me to construct a regex expression that grabs anything between the : and the ; but I haven’t been able to make it work.

Any regex pros here? Or someone else with a better idea?

Hi there, @ian11… if I understand your post correctly, you can use two :split by operators to get what you need. Take the string and split by a colon and grab the last item… then split the resulting sting by a semi-colon and grab the first item. The result will be image/jpeg.

Example:

split

Hope this helps.

Best…
Mike

1 Like

That’s really great! Thanks for your help!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.