[英]I'm trying to write a function to simplify string concatenations inside an string. e.g. ' “abc” + “defg” ' turns into ' “abcdefg” '
很难解释,但我需要一个函数来做这样的事情:
输入: cleanStr(" console.log('abc' + 'defg') ")
输出: "console.log('abcdefg')"
输入: cleanStr(" console.log(['abc' + \\"123\\", 'other', 'other']) ")
输出: "console.log(['abc123', 'other', 'other'])"
输入: cleanStr(" console.log({ "key": \\"abc\\" + 'def', "other": ('hello ') + 'world' }) ")
输出: "console.log({ "key": \\"abcdef\\", "other": 'hello world' })"
我所有的尝试在其中一些测试中都失败了 /\\
尝试运行" ['abc' + 'defg', 'abc', 'abc'] "
,输出将正是我希望我的函数返回的内容,但在字符串上。
规则:
"
和'
()
例如('string') + 'string'
' + '
而不是', '
eval
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.