2013-01-13 2 views
0

밑줄 번호가 포함 된 모든 단어에서이 문자열을 제거해야하는 문자열이 있습니다. 내가 찾고 있어요문자열에서 문자와 숫자를 제거하는 Javascript 정규식

"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 출력은 다음과 같습니다

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

할 수 있습니다. 제거 작업을 키에만 적용하고 싶지 않습니까? – Bergi

+0

JSON처럼 보일뿐 아니라 적용된 변환으로 인해 _illegal_ JSON으로 바뀝니다 (JSON 객체는 중복 키를 가질 수 없습니다 (RFC 4627 참조) – fge

+0

아래에서 해결되었지만 여기에 번호 매기기가있는 이유는 그것은 JSON으로 사용될 때 고유하며, db의 문자열로 저장 될 때 번호 매기기를 제거합니다. 다른 종속성으로 인해 다른 방식으로 구조화 할 수 없습니다. – Rob

답변

2

당신이 너무 많은 JSON처럼 보이는

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