Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Last active August 29, 2015 14:17
Show Gist options
  • Save jasonleonhard/dffe06632348c46ac4ac to your computer and use it in GitHub Desktop.
Save jasonleonhard/dffe06632348c46ac4ac to your computer and use it in GitHub Desktop.
// This will match an email given any string
// note even my ' in the string was fine ;D
var re = /[\w]+@[\w-]+\.[\w]+/g;
var str2 = "my email is not [email protected] it's actually [email protected]";
var myArray = str2.match(re);
myArray
//search inside just a target <tag> in DevTools console using RegEx
//1. then convert that object into a string
var text = $('<div>').append($('#file-gistfile1-txt-LC4').clone()).html(); text;
// "<div class="line" id="file-gistfile1-txt-LC4" style="display: block;">var str2 = "my email is not [email protected] it's actually [email protected]";</div>"
//2. and then use regex to match just emails (of that new string only)
var re = /[\w]+@[\w-]+\.[\w]+/g;
var myArray = text.match(re); myArray
//["[email protected]", "[email protected]"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment