Except where otherwise noted, the contents of this presentation are Copyright 2010 Marty Stepp and Jessica Miller.
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"