C# 用换行符提取文本
我正在使用这个模式C# 用换行符提取文本,c#,regex,C#,Regex,我正在使用这个模式 const string ptnBodytext = @"<p>\s*(.+?)\s*</p>"; 常量字符串ptnBodytext=@“\s*(.+?)\s*”; 以提取标记中的文本。除了带有换行符的文本外,它工作正常,例如: 乱数假文 第二线或 第三个? 如何更改模式以包含换行符、制表符等?只需删除\s*: const string ptnBodytext = @"<p>(.+?)</p>"; 常量字符串ptnB
const string ptnBodytext = @"<p>\s*(.+?)\s*</p>";
常量字符串ptnBodytext=@“\s*(.+?)\s*”; 以提取
标记中的文本。除了带有换行符的文本外,它工作正常,例如:
乱数假文
第二线或
第三个?
如何更改模式以包含换行符、制表符等?只需删除
\s*
:
const string ptnBodytext = @"<p>(.+?)</p>";
常量字符串ptnBodytext=@“(.+?)”;
只需删除
\s*
:
const string ptnBodytext = @"<p>(.+?)</p>";
常量字符串ptnBodytext=@“(.+?)”;
您需要激活dotall模式,或者:
const string ptnBodytext = @"<p>([\s\S]+?)</p>";
常量字符串ptnBodytext=@“([\s\s]+?)”;
请参阅。您需要激活dotall模式,或者:
const string ptnBodytext = @"<p>([\s\S]+?)</p>";
常量字符串ptnBodytext=@“([\s\s]+?)”;
请参阅。如果您正在解析HTML,为什么不使用
。替换(“”,”)。替换(“”,”)
?如果您正在解析HTML,为什么不使用。替换(“”,”)。替换(“”,”)
?没有模式。此外,\s*
匹配零个或多个空白字符。没有模式。另外,\s*
匹配零个或多个空白字符。常量字符串ptnBodytext=@“(.+?)”代码>并在构建regex对象时传递RegexOptions.Singleline
标志。const string ptnBodytext=@“(.+?)”
并在构建regex对象时传递RegexOptions.Singleline
标志。