Description
The search() method searches for a match between a regular expression and a string.
This method has the form:
string.search(regexp)
| Parameter | Description |
|---|---|
| regexp | (required) A regular expression |
Note: This method returns the position of the match, or -1 if no match is found.
Examples
The following example shows the basic use of this method.
<script>
var s = "Hello from JavaScript";
document.write(s.search("Java"));
document.write("<br />");
document.write(s.search("Hawaii"));
</script>
This produces the following result:
Browser Support
| Firefox | IE | Chrome | Opera | Safari |
|---|---|---|---|---|
