Episodes
Saturday Nov 11, 2006
Javascript RegExp -1
Saturday Nov 11, 2006
Saturday Nov 11, 2006
In javascript, the RegExp object has a method called test(), which simply returns true if the given string (the only argument) matches the pattern and false if not:
var sMyString = "get a dog"; var regPattern = /dog/; alert(regPattern.test(sMyString)); //outputs "true"The RegExp exec() method, which takes a string as an argument, returns an Array containing all matches. Consider the following example:
var sToMatch = "a bat, a Cat, a fAt baT, a faT cat";
var reAt = /at/g;
var arrMatches = reAt.exec(sToMatch);
The replace() method, which replaces all occurrences of a substring (the first argument) with a different string (the second argument). For example:
var sToChange = "The sky is red. "; alert(sToChange.replace("red", "blue")); //outputs "The sky is blue."
Version: 20240320
Comments (0)
To leave or reply to comments, please download free Podbean or
No Comments
To leave or reply to comments,
please download free Podbean App.