Link to home
Start Free TrialLog in
Avatar of wildrobo
wildroboFlag for United States of America

asked on

RegExp find tags

I have a long  string that has tags i.e. <row> <cell> etc.

I would like to use a regexp to find all the occurences

I.E.

Dim re As New Regex("<.+>")
        Dim mc As MatchCollection = re.Matches(rtbFormattedText.Text)
        Dim m As Match
        For Each m In mc
            Console.WriteLine(m.ToString)
        Next

the problem is it returns the following line as a single match
<f name="Nobel-Regular"><z newsize="24.0"><color name="LexusGold">

How do I return each <*> using regexp?

The point I am trying to acheive is
The text is in a richtext box, when the text changes in the box, I want to go through and highlight all the tags.  Anything in <>.  I was going to use a regexp then find the position start of the match in the RTB and the length, then highlight it.  If anyone can think of a better way, I will except that as well.

Thanks
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Try it this way.

    Dim re As New Regex("<.+?>")

Fernando
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wildrobo

ASKER

Awesome,
   Thank you.  Not only for the actual code, but more importantly for the explination.  "Teach a man to fish...." right.


Thanks again.
Not a problem, always glad to help if I can. ;=)