使用正则表达式从带引号的字符串中删除引号 [英] Remove quotes from quoted string using regex

查看:95
本文介绍了使用正则表达式从带引号的字符串中删除引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像

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

我想用 TRUE AND FALSE 替换所有 "TRUE""FALSE".

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

现在结果字符串应该是

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)

注意:现在我知道你们会说这不是一个建设性的问题,应该结束,但我问这个的原因是因为我想出了什么,必须写下来两次 TRUEFALSE 一次,这不是想要的结果,相反,我希望正则表达式只查找和替换一次.此外,我必须绝对确定我的正则表达式不会错过任何模式.最后,如果您认为这不够有建设性,那么请继续关闭它.

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.

推荐答案

使用

"(TRUE|FALSE)"

并替换为

$1

在 VB.NET 中这变成了

In VB.NET this becomes

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

如果您还有其他问题,请告诉我们

Let us know if you have any more questions

这篇关于使用正则表达式从带引号的字符串中删除引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆