"abbbc" Anchors // ^ - string starts with // $ - string ends with if (/^My/.test("My name is Tom")) console.log ("Hi!"); if (/Tom$/.test("My name is Tom")) console.log ("Hi Tom!"); Subexpression // ( ) - groups characters if (/water(mark)?/.test("watermark")) console.log("Here is water!"); // match: "water", "watermark", if (/(Tom)|(John)/.test("John")) console.log("Hi Tom or John!"); Flags // /g - global // /i - ignore upper/lower case // /m - allow matches to span multiple lines console.log("hi tom!".replace(/Tom/i, "John")); // == "hi John!" console.log("ratatam".replace(/ta/, "tu")); // == "ratutam" console.log("ratatam".replace(/ta/g, "tu")); // == "ratutum" Advanced methods my_array = my_string.split(my_delimiter); // example my_array = "dog,cat,cow".split(","); // my_array==["dog","cat","cow"]; my_array = my_string.match(my_expression); // example my_array = "We start at 11:30, 12:15 and 16:45".match(/\d\d:\d\d/g); // my_array==["11:30","12:15","16:45"]; Capturing groups var myRe = /(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})/; var results = myRe.exec("The date and time are 2009-09-08 09:37:08."); if (results) { console.log("Matched: " + results[0]); // Entire match var my_date = results[1]; // First group == "2009-09-08" var my_time = results[2]; // Second group == "09:37:08" console.log("It is " + my_time + " on " + my_date); } else console.log("Did not find a valid date!"); Function Every function in JavaScript is an instance of the Function constructor: // x, y is the argument. 'return x + y' is the function body, which is the last in the argument list. var add = new Function('x', 'y', 'return x + y'); add(1, 2); // => 3 The add function above may also be defined using a function expression: var add = function(x, y) { return x + y; }; add(1, 2); // => 3 In ES6, arrow function syntax was added, allowing functions that return a value to be more concise. They also retain the this of the global object instead of inheriting it from where it was called / what it was called on, unlike the function() {} expression. var add = (x, y) => {return x + y;}; // values can also be implicitly returned (i.e. no return statement is needed) var addImplicit = (x, y) => x + y; add(1, 2); // => 3 addImplicit(1, 2) // => 3 For functions that need to be hoisted, there is a separate expression: function add(x, y) { return x + y; } add(1, 2); // => 3 Hoisting allows you to use the function before it is "declared": add(1, 2); // => 3, not a ReferenceError function add(x, y) { return x + y; } A