Quick References
ADO
ASP
CSS2
HTML
JavaScript
Jet SQL
VBScript
WML
WMLScript
WSH
XHTML
XML DOM
XSLT
Features
Knowledge Base
Tutorials
Partners
ZVON.ORG
XML
Planet Source Code
VisualBuilder
Web Design
Your HTML Source
XML/XSLT Forums
ASPAlliance
Scripts
Programmers Heaven
Tek-Tips Forums
Developer Fusion
Code Project
All Objects
String Object
METHOD: String::search
object.
search
(regexp)
This method is used to search for a match between a regular expression and the specified string. If a match is found, the search method returns the index of the regular expression within the string. If no match is found, a value of -1 is returned.
The first example of code below uses the
search
method to look for a match between the regular expression 'rExp' and the characters in the 'myString' string object and displays the resulting value in the browser. In the second example, removing the 'i' (ignore case) flag from the regular expression causes the value of the search to be returned as -1
Code:
myString = new String("Go to DevGuru.com")
rExp = /devguru.com/gi;
results = myString.search(rExp)
document.write(results)
Output:
6
myString = new String("Go to DevGuru.com")
rExp = /devguru.com/g;
results = myString.search(rExp)
document.write(results)
Output:
-1
Copyright 1999-2005 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information