定期表达fidn重复< br>在一个字符串中 [英] Regular expresion to fidn repeated <br> in a string
问题描述
HI
我想做的是只替换多个< br>标签同时发生....< br>< br>< br>< br> ...应该被单个< br>替换标签。
HI
what I m trying to do is to only replace multiple <br> tags occurring simultaneously e.g. ....<br><br><br><br>... should be replaced by single <br> tag.
result = Regex.Replace(result, "(\r)( )+(\r)", "\r\r", RegexOptions.IgnoreCase);
我试过
I have tried
{<br>}( )+{<br>}
[<br>]( )+[<br>]
(<br>)( )+(<br>)
但它不起作用。
谢谢,
But it doesn't work.
Thanks,
A
推荐答案
如果要替换所有
<br>
使用,尝试使用Regex.Replace()方法:
with "", try Regex.Replace() method:
Imports System
Imports System.Text.RegularExpressions
Public Module Module1
Public Sub Main()
' original string
Dim input As String = "blah<br> blah<br>,,,"
Dim output As String = Regex.Replace(input, "<br>", "")
' print out
Console.WriteLine(input)
Console.WriteLine(output)
End Sub
End Module
++++ [第2轮] +++++
如果您打算替换连续的休息时间,例如
++++[Round 2]+++++
If you meant to replace consecutive breaks like
blah<br><br>blah
一张
with a single
<br>
然后试试这个:
then try this:
Dim input As String = "blah<br> blah<br><br>,,,"
Dim output As String = Regex.Replace(input, "(<br>){2,}", "<br>")
{2,}表示前面两种或多种模式。
{2,} means 2 or more of the preceding pattern.
试试这个:
Dim Your_String As String = "dsfsdfsdfsdfs <br> dsfsdfsdfsdfsdf <br><br><br><br><br><br> sdfsdf <br><br> sdfgssdg <br><br><br> sdfdsf <br> dssfsf <br>"
Dim options As RegexOptions = RegexOptions.None
Dim regex As New Regex("[<br>]{2,}", options)
Your_String = regex.Replace(Your_String, "<br>")
参考: http://stackoverflow.com/a/206720/2645738 [ ^ ]
问候..
Reference : http://stackoverflow.com/a/206720/2645738[^]
Regards..
这篇关于定期表达fidn重复< br>在一个字符串中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!