Except where otherwise noted, the contents of this document are Copyright 2012 Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
string.match(regex)
null
var name = $("name").value;
if (name.match(/[a-z]+/)) { ... }
i
can be placed after the regex for a case-insensitive match
name.match(/Marty/i)
will match "marty"
, "MaRtY"
, ...string.replace(regex, "text")
var str = "Marty Stepp";
str.replace(/[a-z]/, "x")
returns "Mxrty Stepp"
str = str.replace(/[a-z]/, "x")
g
can be placed after the regex for a global match (replace all occurrences)
str.replace(/[a-z]/g, "x")
returns "Mxxxx Sxxxx"
str = str.replace(/[^A-Z]+/g, "")
turns str
into "MS"