An email extractor is a tool that helps extract email addresses from a given data source. In the context of Google Sheets, a custom Apps Script formula can extract email addresses from a range of cells.
Here’s an example of a custom formula code for extracting email addresses:
function extractEmails(text) {
var regex = /[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
var emails = [];
var matches = text.match(regex);
if (matches) {
for (var i = 0; i < matches.length; i++) {
emails.push(matches[i]);
}
}
return emails.join(", ");
}
Explanation:
The extractEmails
function takes a text string as input and returns a comma-separated string of email addresses that were found in the input text.
The regular expression used in this function (/[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g
) matches any valid email address format.
The function then creates an empty array (emails
) to store the extracted email addresses. It uses the match
method of the input text to find all matches of the regular expression and store them in the matches
array.
Finally, the function uses a for
loop to iterate through the matches
array and push each email address into the emails
array. It then uses the join
method to convert the emails
array into a comma-separated string of email addresses.
To use this custom formula in Google Sheets, enter the following formula into a cell:=extractEmails(A1)
where A1
is the cell containing the text from which you want to extract email addresses.
This custom formula can be very useful for extracting email addresses from large datasets, such as email lists or contact lists, making it much quicker and easier to manage and use the extracted information.