Skip to content
Advertisement

Extract email address from string in Javascript (Google Tag manager function)

I’m looking for a way to extract the email address from a string I have already stored in a Google Tag Manager variable. I’m new with Javascript and I tried some functions I found on the internet but they all return “undefined”

Example :

JavaScript

My string is : ‘ You are now logged as John Doe (john.doe@gmail.com) ’ (the incorrect caracters are linked with fontawesome library problem, fixed soon) I would like to run a JS/Tag Manager function that return only john.doe@gmail.com

The Google Tag Manager functions should not use librairies and should be a JavaScript function that returns a value using the ‘return’ statement. Thanks for you help.

Regards.

Advertisement

Answer

This should do the job for your String:

JavaScript
Advertisement