删除问号以外的所有内容 [英] Remove everything except question mark
问题描述
您好,
我有以下html模式: < td>< b> 其中 < / b>< / td>< br>< br>
I have the following html pattern: <td><b>Where</b></td><br><br>
在上述模式中,字符串其中可以替换为任意数量的字词(包括多个字词:
节目名称)。
In the above pattern, the string Where could be substituted with any number of words (including multiple words: Program Name).
我是能够通过使用以下正则表达式来找到该html模式:
。*
I am able to locate that html pattern by using the following regex expression: .*
有些情况下,html标记中包含的字符串包含一个问题标记(?),例如:
There are instances where strings enclosed within the html tags include a question mark (?) such as in this:
< td>< b> 你多大了? < / b>< / td>< br>< br>。
任何人都可以帮助我识别这些模式?
我已经构建了一个删除已识别模式的函数,但在这种情况下,我希望删除上述html标记中的所有字符串,除非它们包含问号。
我的函数看起来像这样:myFunction(pattern,replacementstring,originalstring)
运行以下代码:myFunction (。*,'',myString)应该返回一个空格('')
如果我想要替换所有内容,那将是什么样的正则表达式单词字符串,如果以问号结尾(?)
谢谢
Thank you
推荐答案
检查此示例:
string text = "<td><b>Where</b></td><br><br><td><b>How old are you ?</b></td><br><br>";
string result = Regex.Replace( text, @"(?<=>)[^<>]+[^?](?=<)", "" );
这篇关于删除问号以外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!