我正在使用正则表达式来获取HTML中两个字符串之间的字符串.在里面
Regex101正如预期的那样令人担忧.但是在.NET中它没有包装我想要的字符串.下面是代码:
html = Regex.Replace(html, @"(?<=<strong>CNPJ:)(.*?)(?=hddServidorCaptcha)\s*", string.Empty);
Run Code Online (Sandbox Code Playgroud)
唯一的区别是我/s在网站上指定了.但.NET中的默认值是/g.有没有办法改变它?谢谢
您可以使用相同方法的重载:
html = Regex.Replace(html, @"(?<=<strong>CNPJ:)(.*?)(?=hddServidorCaptcha)\s*", string.Empty, RegexOptions.SingleLine);
Run Code Online (Sandbox Code Playgroud)