4 Replies - 260 Views - Last Post: 28 October 2017 - 03:56 AM Rate Topic: -----

#1 damlays  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-October 17

How to capture text inside <TAGs> , BUT by excluding the tags

Posted 27 October 2017 - 08:12 AM

In Visual Basic I am trying to get text between tags but TAGS are also captured.


    Public Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim pattern As String = "<tag>(.+?)<\/tag>"

    Dim text As String = "Other Text <tag>Captured Text</tag> Other Text"

    Dim capture As Match = Regex.Match(text, pattern)

    MsgBox(capture.Value)

End Sub



I want to see the result as ONLY "Captured Text" in message box.

But result is coming as "...Captured Text...." with both tags before and after .

What is wrong in my code?

Is This A Good Question/Topic? 0
  • +

Replies To: How to capture text inside <TAGs> , BUT by excluding the tags

#2 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,770
  • Joined: 12-December 12

Re: How to capture text inside <TAGs> , BUT by excluding the tags

Posted 27 October 2017 - 08:20 AM

It is probably something like capture.Groups(1) or capture.Groups(1).Text. Anyway, you are trying to retrieve the data of the 1st capture group.
Was This Post Helpful? 1
  • +
  • -

#3 IronRazer  Icon User is offline

  • Custom Control Freak
  • member icon

Reputation: 1445
  • View blog
  • Posts: 3,679
  • Joined: 01-February 13

Re: How to capture text inside <TAGs> , BUT by excluding the tags

Posted 27 October 2017 - 12:59 PM

Yep, the Value property seems to be the one....
MsgBox(capture.Groups(1).Value)

Was This Post Helpful? 1
  • +
  • -

#4 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,770
  • Joined: 12-December 12

Re: How to capture text inside <TAGs> , BUT by excluding the tags

Posted 27 October 2017 - 01:47 PM

I thought it would be Value ;) but also wanted the OP to do a little work :)
Was This Post Helpful? 1
  • +
  • -

#5 damlays  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-October 17

Re: How to capture text inside <TAGs> , BUT by excluding the tags

Posted 28 October 2017 - 03:56 AM

Yes, Groups(1) is the solution..Thank you very much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1