运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Regular Expressions</h2> <p>Do a global search for "Hello" and "W3Schools" in a string:</p> <p id="demo"></p> <script> let text = "Hello world!"; // look for "Hello" let pattern1 = /Hello/g; let result1 = pattern1.test(text) // look for "W3Schools" let pattern2 = /W3Schools/g; let result2 = pattern2.test(text); document.getElementById("demo").innerHTML = result1 + "<br>" + result2; </script> </body> </html>