简体   繁体   English

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

[英]Javascript regex to remove character and number from string

I have this String that I need to remove the underscore number from all words that contain them. 我有这个字符串,我需要从包含它们的所有单词中删除下划线数字。

"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]}}

I output i am looking for is: 我正在寻找的输出是:

"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, '')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM