开发者

Using regex to remove all newlines within <li> </li>

I have a st开发者_Go百科ring like this

<li>something is\n here</li>

but it should be

<li>something is here</li>

Any ideas?


Use a Regex replace:

(?<=<li>.*?)\n(?=.*?</li>)

I've used it like instead of \n, I've tested it with the letter e:
<li>elelele</li> results in <li>lll</li>
eee<li>elele</li>e results in eee<li>ll</li>e


You could always read the HTML into a string and then do string manipulations on the <li>something is\n here</li> using the indexof() property to get the correct position and then remove the \n using the string.replace() functionality. Unless you have to use Regex this would work just as well!


string html1 = "<li>something is\n here</li>";
            html1 = html1.Replace("\n", "");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜