用自己的修改版本替换任何单词 [英] Replace any words with modified version of themselves

查看:73
本文介绍了用自己的修改版本替换任何单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法来改变这个字符串:

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

(java || javascript) && vbscript

进入此字符串:

(str.search('java') || str.search('javascript')) && str.search('vbscript')

即用 str.search('+ word +')

我看过 mystring.match( / [ - \w] + / g); 将任何单词拉出到数组中(但不是它们的位置)

I've looked at mystring.match(/[-\w]+/g); which will pull any words out into an array (but not their position)

推荐答案

您可以致电替换

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

请注意,这是一个XSS漏洞,因为用户输入可以包含' s。

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

这篇关于用自己的修改版本替换任何单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆