Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Search Text or Pattern inside a String</title> </head> <body> <script> let str = "Color red looks brighter than color blue."; // Case sensitive search let pos1 = str.search("color"); document.write(pos1 + "<br>"); // 0utputs: 30 // Case insensitive search using regexp let pos2 = str.search(/color/i); document.write(pos2); // 0utputs: 0 </script> </body> </html>