Remove quotes from quoted string using regex

懵懂的女人 提交于 2020-01-06 03:22:08

问题


I have a string like

FVAL(XXX)="TRUE" AND FVAL(TT)="FALSE" 

I want to replace all "TRUE" and "FALSE" by TRUE AND FALSE.

Now the resultant string should be

FVAL(XXX)=TRUE AND FVAL(TT)=FALSE

Will the code shown below be upto the mark for this.

Regex.Replace("FVAL(XXX)=""TRUE"" AND FVAL(TT)=""FALSE""", "[""]TRUE[""]", "TRUE", RegexOptions.IgnoreCase)

Note: Now I know you guys would say that this is not a constructive question and should be closed, but the reason I asked this is because what I came up with, will have to be written twice once for TRUE and once for FALSE, which is not the desired result, instead I want the regex to find and replace just once. Also I have to be absolutely sure that my regex would not miss out any pattern. And lastly if you think this is not constructive enough, then please go ahead and close it.


回答1:


USe

"(TRUE|FALSE)"

and replace it by

$1

In VB.NET this becomes

ResultString = Regex.Replace(SubjectString,
    """(TRUE|FALSE)\""", "$1", 
    RegexOptions.Singleline)

Let us know if you have any more questions



来源:https://stackoverflow.com/questions/10980141/remove-quotes-from-quoted-string-using-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!