<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> var past=/helloword/gi; var str='helloword my HelloWord baby'; console.log(past.test(str));//返回true or false console.log(past.exec(/aa/));//返回匹配到的字符串及其位置 匹配不到返回null console.log(past.exec(str));//返回匹配到的字符串及其位置 匹配不到返回null console.log(str.match(past));//返回匹配到的字符串 匹配不到返回null console.log(str.match(/aa/));//返回匹配到的字符串 匹配不到返回null console.log(str.search(/1/));//返回匹配到的字符串位置 匹配不到返回-1 console.log(str.replace(past,"你好"));//字符串替换 console.log(str.split(' '));//字符串拆分成数组 console.log(str.split(/s+/));//s+匹配空字符串 </script> </head> <body> </body> </html>