Replace any words with modified version of themselves

前端 未结 2 1525
广开言路
广开言路 2021-01-25 13:38

I\'m looking for an easy way to turn this string:

(java || javascript) && vbscript

Into this string:

(str.search(\'java         


        
2条回答
  •  清歌不尽
    2021-01-25 13:51

    Just a fixed version with correct capture and using 1 as backtrack index. See details in "Specifying a string as a parameter" section of String.replace.

    mystring.replace(/([-\w]+)/g, "str.search('$1')");
    

提交回复
热议问题