Referencia de JavaScript 1.5:Objetos globales:String:search
De MDC
Tabla de contenidos |
[editar] Resumen
Ejecuta la búsqueda que encaje entre una expresión regular y este objeto String.
| Método de String | |
| Implementado en: | JavaScript 1.2 |
| Versión ECMA: | ECMA-262, Edición 3 |
[editar] Sintaxis
search(expresionreguarl)
[editar] Parámetros
-
expresionreguarl - Un objeto expresión regular. Si se pasa un objeto no expresión regular
obj, se convierte implicitamenteenuna expresión regualar usandonew RegExp(obj).
[editar] Description
If successful, search returns the index of the regular expression inside the string. Otherwise, it returns -1.
When you want to know whether a pattern is found in a string use search (similar to the regular expression test method); for more information (but slower execution) use match (similar to the regular expression exec method).
[editar] Examples
[editar] Example: Using search
The following example prints a message which depends on the success of the test.
function testinput(re, str){
if (str.search(re) != -1)
midstring = " contains ";
else
midstring = " does not contain ";
document.write (str + midstring + re.source);
}