Replace any words with modified version of themselves

前端 未结 2 1523
广开言路
广开言路 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:59

    You can call replace:

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

    Note that this is an XSS hole, since the user input can contain 's.

提交回复
热议问题