anElement.innerHTML = "Indonesia".search(/do/i); // return 4
output> 4
elem.innerHTML = "indonesia".split(/[aiueo]/);
output> ,nd,n,s,, // 6 array elements
elem.innerHTML = /wo/.test("Hello world");
output> true;
String method for Regex:
1. search(pattern) : index
2. split(pattern) : array >< match
3. replace(pattern,textReplacer): string
4. match(pattern) : array >< splitvar hello = "Hello world";
elem.innerHTML = hello.search(/world/ig); output> 6
elem.innerHTML = hello.split(/[aiueo]/ig);output> h,ll, w,rld
elem.innerHTML = hello.replace(/world/,"lady gaga");output> hello lady gaga
elem.innerHTML = hello.match(/[aiueo]/);
output> e,o,o
No comments:
Post a Comment