Iakov
0
Q:

match js

<script> 
  
    // initializing function to demonstrate match() 
    // method with "i" para 
    function matchString() { 
        var string = "Welcome to GEEKS for geeks!"; 
        var result = string.match(/eek/i); 
        document.write("Output : " + result); 
    } matchString(); 
      
</script>                     
7
// The match() method searches a string for a match against a regular expression,
// and returns the matches, as an Array object.
// If the regular expression does not include the g modifier (to perform a global search),
// the match() method will return only the first match in the string.
// This method returns null if no match is found.

let str = "The rain in SPAIN stays mainly in the plain"; 
let res1 = str.match(/ain/g); /* ["ain", "ain", "ain"] */
let res2 = str.match(/ain/); /* ["ain", index: 5, input: "The rain in SPAIN stays mainly in the plain", groups: undefined] */
let res3 = str.match(/blah/); /* null */
 
4
const match = 'some/path/123'.match(/\/(\d+)/)
const id = match[1] // '123'
2
cadena = "Para más información, vea Capítulo 3.4.5.1";
expresion = /ver/i;
incluye = cadena.match(expresion);
console.log(incluye);
-1

New to Communities?

Join the community