替换
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title>RegExp</title> </head> <body> <script> var reg=new RegExp("Paul","g"); var stringObj="Paul Paula paul sPaul Paul"; var newstr=stringObj.replace(reg,"Ringo"); alert(newstr); </script> </body> </html>
结果