Javascript正则表达式从字符串中删除字符和数字

标签 javascript regex string replace

我有这个字符串,我需要从包含它们的所有单词中删除下划线数字。

"View":{"Name":"Untitled-4","Image_1":{"BackgroundImage":"Image.png","Position":[0,0],"Width":320,"Height":480},"Button_1":{"BackgroundImage":"ButtonTop.png","Position":[61,83],"Width":217,"Height":58},"Button_2":{"BackgroundImage":"ButtonBottom.png","Position":[81,114],"Width":205,"Height":73},"TextField_1":{"BackgroundImage":"TextFieldLogin.png","Position":[102,336],"Width":189,"Height":31},"Label_1":{"Position":[137,100],"Width":54,"Height":20,"Text":"HiRob","FontSize":18,"Color":[0,0,0,1]},"Label_2":{"Position":[43,342],"Width":72,"Height":20,"Text":"LogOut:","FontSize":18,"Color":[0,0,0,1]},"Label_3":{"Position":[115,234],"Width":126,"Height":20,"Text":"AnotherButton","FontSize":18,"Color":[0,0,0,1]}}

我要查找的输出是:

"View":{"Name":"Untitled-4","Image":{"BackgroundImage":"Image.png","Position":[0,0],"Width":320,"Height":480},"Button":{"BackgroundImage":"ButtonTop.png","Position":[61,83],"Width":217,"Height":58},"Button":{"BackgroundImage":"ButtonBottom.png","Position":[81,114],"Width":205,"Height":73},"TextField":{"BackgroundImage":"TextFieldLogin.png","Position":[102,336],"Width":189,"Height":31},"Label":{"Position":[137,100],"Width":54,"Height":20,"Text":"HiRob","FontSize":18,"Color":[0,0,0,1]},"Label":{"Position":[43,342],"Width":72,"Height":20,"Text":"LogOut:","FontSize":18,"Color":[0,0,0,1]},"Label":{"Position":[115,234],"Width":126,"Height":20,"Text":"AnotherButton","FontSize":18,"Color":[0,0,0,1]}}

最佳答案

你可以做到

var replaced = str.replace(/_\d+/g, '')

关于Javascript正则表达式从字符串中删除字符和数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14308532/

相关文章:

javascript - requestAnimationFrame感到困惑

javascript - 如何在 Firebase 触发事件中检索子集合项的父级

python - 检查列表是否有一个或多个匹配正则表达式的字符串

Java正则表达式匹配元组

string - 从字符串到结构 Golang

javascript - 使用 HTMLImports.whenReady 在 Chrome 中不起作用

javascript - 将 HTML 元素放在 map 图 block 上

包含小数点的数字的正则表达式

java - 我可以根据其字段的值获取枚举吗?

javascript - 提取元素内的所有有效 URL 字符串 (JavaScript)