Skip to content

Instantly share code, notes, and snippets.

@jasonleonhard
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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 optikalefx@me.com it's actually devbrights@gmail.com";
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 optikalefx@me.com it's actually devbrights@gmail.com";</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
//["optikalefx@me.com", "devbrights@gmail.com"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment