Javascript examples for String Operation:String Convert
Use Regex to insert text to a string
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w . ja v a 2 s . com*/ var re = /(function\s+.*\(\)\s+{)(.*)/; var str = 'function test() {\n//some code...\n}'; var newstr = str.replace(re, '$1\n \'use strict\';\n$2'); document.write(newstr); } </script> </head> <body> </body> </html>