需要帮助查找和替换“{#ANY_TEXT#}”的文本 [英] Need help finding and replacing text for "{#ANY_TEXT#}"

查看:112
本文介绍了需要帮助查找和替换“{#ANY_TEXT#}”的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我需要您的专家帮助。我正在尝试找到一个正则表达式来替换引号之间的所有文本"{#ANY_TEXT#}"

I need your expert help.  I'm trying to find a regular expression to replace all text between quotes "{#ANY_TEXT#}"

例如,如果我的字符串类似于"这是一个测试{ #ANY_TEXT#} string"。我需要从{#...#}开始用另一个值替换所有内容。例如,如果我想将其设为空白,则最终结果应为"This is a test string"。可能有几个这样的例子。

For example, if I have string like "This is a test {#ANY_TEXT#} string".  I need to replace everything starting from {#...#} with another value.  For example, If I want to make it blank, then end result should be "This is a test string".  There could be several instances of this.

提前感谢您的帮助。

Andrew

推荐答案

由于这可能留下额外的空间,我们可以假设{#ANY_TEX#}永远不会出现在字符串的开头或结尾吗?或者可以吗?换句话说,我们也可以在你的例子中做这样的事情来消除它。

Since this may leave an extra space, can we assume that {#ANY_TEX#} will never be at the start of string or at the end? Or can it be?. In other words we can also do something like this in your example to eliminate that.

String word = "This is a test {#ANY_TEXT#} string";
String pattern = @"\{[^\}]*\}\s(\w)";
word = Regex.Replace(word, pattern, "


1");
Console.WriteLine(word);
Console.ReadLine();
1"); Console.WriteLine(word); Console.ReadLine();


这篇关于需要帮助查找和替换“{#ANY_TEXT#}”的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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