Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C中的通配符替换正则表达式_C#_Regex_Replace - Fatal编程技术网

C# C中的通配符替换正则表达式

C# C中的通配符替换正则表达式,c#,regex,replace,C#,Regex,Replace,我搜索了又搜索,看到了一些看起来像解决方案的代码,但它不起作用。我没有使用正则表达式的经验,我想看看我在这里做错了什么 string line = input.Replace("<td>", ";"); string withoutTabs = Regex.Replace(line, "\t", ";"); string withoutTD = Regex.Replace(withoutTabs, ".*</td>", ";"); 上面的代码试图替换HTML表布局中的所

我搜索了又搜索,看到了一些看起来像解决方案的代码,但它不起作用。我没有使用正则表达式的经验,我想看看我在这里做错了什么

string line = input.Replace("<td>", ";");
string withoutTabs = Regex.Replace(line, "\t", ";");
string withoutTD = Regex.Replace(withoutTabs, ".*</td>", ";");
上面的代码试图替换HTML表布局中的所有和选项卡。但它不起作用,它不会移除标签,也不会替换标签。标签通常附加到一些文本上,如:text

我希望它看起来像这样:文本

有人能指出我的错误吗,或者我的正则表达式都错了,我需要用别的东西来代替它吗

我想用替换以及和选项卡

那不是:

string withoutEndTD = Regex.Replace(withoutTabs, "</td>", ";");
这实际上是相同的做法:

string withoutEndTD = withoutTabs.Replace("</td>", ";");

如果您想获取任何的innerText文本,那么无论是RegExp还是string.Replace都不是一个好办法。您可以使用DOM处理,比如Linq到XML。

使用line=line.Replace@\t;;不带tabs的字符串=Regex.Replaceline,@\t@AvinashRaj为什么@before the \totherwise会将\t视为转义序列。string withoutTabs=Regex.Replaceline,\\t;;所以如果我想添加,比如说,或者,它变成这样:Regex.Replaceinput,@|\t |;;Regex.Replaceinput@|\t;;,这将用分号替换打开和关闭td、tr和制表符。谢谢,现在一切正常。我还有一个问题,如何用regExp替换?只需将原始regex与子字符串连接起来,但必须转义特殊字符。Regex.Replaceinput,@|\t |;;
string withoutEndTD = withoutTabs.Replace("</td>", ";");