none
Regex - Reverse Search RRS feed

  • Question

  • Suppose I have the following string:

    <a>qwe15</a>  <a>Hello4xc</a> <a>Hello10Right</a>

    and now, i want to find "<a> Hello10Right </ a>" word, so i will use next  Pattern: "<a>.*?<\/a>"

    now, it will find all words that start with: "<a>" and ends with: "</a>"

    What is inside the tag: "<a>" is Variable.

    I do not know what the length of the string - is also Variable.





    • Edited by YouAndMe75 Saturday, April 13, 2013 4:12 PM
    Saturday, April 13, 2013 4:09 PM

Answers

  • You can try following Regex pattern

    <a([^>]*)>(.+?)</a>

    Following code should work

    Dim str As String = "<a>qwe15</a>  <a>Hello4xc</a> <a>Hello10Right</a>"
    Dim r As New Regex("<a([^>]*)>(.+?)</a>")
    Dim matches As MatchCollection = r.Matches(str)
    For Each m As Match In matches
        MessageBox.Show(m.Value)
    Next

    If you want to search in reverse direction then you can try following code

     Dim r As New Regex("<a([^>]*)>(.+?)</a>", RegexOptions.RightToLeft)


    Gaurav Khanna | Microsoft VB.NET MVP | Microsoft Community Contributor

    • Marked as answer by YouAndMe75 Saturday, April 13, 2013 10:57 PM
    Saturday, April 13, 2013 7:11 PM