1

Say the string is something like

bla bla bla bla (cat) bladfdskdfd dsgdsdksf (dog) dfdshfdskdskfsdfkhsdf sdkfhdsfkdf (kathy) fdsfhdskfhdsfkd (doggy)

I want a generic.list (of string) containing

cat

dog

kathy

doggy

How to do that with regular expression in vb.net

Later I want to do something more complicated like getting all strings between "url":" and ", from this strings

google.search.WebSearch.RawCompletion('1', {"results":[{"GsearchResultClass":"GwebSearch","unescapedUrl":"https://eproc.pu.go.id/publik/eproc2011/semieprocplus/info_lelangprogress.asp?tid\u003d12\u0026id\u003d%7BC0B5ED00-F369-4700-B93A-B0677B63D9EA%7D\u0026u\u003d7\u0026t\u003d3\u0026d\u003d1","url":"https://eproc.pu.go.id/publik/eproc2011/semieprocplus/info_lelangprogress.asp%3Ftid%3D12%26id%3D%257BC0B5ED00-F369-4700-B93A-B0677B63D9EA%257D%26u%3D7%26t%3D3%26d%3D1","visibleUrl":"eproc.pu.go.id","cacheUrl":"","title":"Informasi Proyek","titleNoFormatting":"Informasi Proyek","content":"Jl. batu \u003cb\u003eKucing\u003c/b\u003e Gg. Tuah No.4 Tanjungpinang. NPWP : 152742110214000. No. Agency, : -. Tgl. Agency, : -. Nilai, : 90.76. Waktu, : 270 Hari. Nilai kontrak, : Rp."},{"GsearchResultClass":"GwebSearch","unescapedUrl":"https://eproc.pu.go.id/publik/dinaspu/kegiatan/info_paket.asp?id\u003d%7B4BD47F74-233B-4D49-BB60-4229023668C6%7D","url":"https://eproc.pu.go.id/publik/dinaspu/kegiatan/info_paket.asp%3Fid%3D%257B4BD47F74-233B-4D49-BB60-4229023668C6%257D","visibleUrl":"eproc.pu.go.id","cacheUrl":"","title":"Informasi Proyek","titleNoFormatting":"Informasi Proyek","content":"9 Apr 2010 \u003cb\u003e...\u003c/b\u003e Sub Kegiatan, : PEMBANGUNAN JALAN. Paket, : Peningkatan jalan s.d hotmix Jl . \u003cb\u003eKucing\u003c/b\u003e Kel.Purwosari. Rupiah Murni, : 1449000000 \u003cb\u003e...\u003c/b\u003e"}],"cursor":{"resultCount":"10","pages":[{"start":"0","label":1},{"start":"4","label":2},{"start":"8","label":3}],"estimatedResultCount":"10","currentPageIndex":2,"moreResultsUrl":"http://www.google.com/search?oe\u003dutf8\u0026ie\u003dutf8\u0026source\u003duds\u0026start\u003d12\u0026hl\u003den\u0026q\u003d+kucing+site:eproc.pu.go.id","searchResultTime":"0.05"}}, 200, null, 200)

4
  • 1
    The parentheses are around the words I want. In the future it won't be parantheses. It'll be something as complex as something else. Commented Apr 6, 2012 at 6:54
  • +1 - This is much more clear and will help you get a great answer :) One suggestion though, that looks like JSON text in areas. Are you able to get JSON data and convert deserialize it into an object? That might be easier than Regex. Commented Apr 6, 2012 at 6:59
  • Hmm.. Yea json parser seems to be the way to go. Does vb.net support json parser? Commented Apr 6, 2012 at 7:01
  • stackoverflow.com/q/1259817/552792 or stackoverflow.com/q/5451119/552792 Commented Apr 6, 2012 at 7:04

2 Answers 2

1

If you want to extract values from string and generate generic list in vb.net you can try it

Private Function Fetch_Items(Text As String) As List(Of Generic_List)
Dim pattern As String = "\((?<value>(.)*?\))"
Dim _lst As New List(Of Generic_List)()
Dim VDMatch As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Match(Text, pattern)
While VDMatch.Success
    _lst.Add(VDMatch.Groups("value").Value)
    VDMatch = VDMatch.NextMatch()
End While

Return _lst
End Function

This function will extract all strings containing within ( ) and generate generic list.

Sign up to request clarification or add additional context in comments.

3 Comments

where can I learn more about "((?<value>(.)*?))" anyway, +1 and selected as accepted answer
(?<[id]>[pattern]) where id will be used to fetch value which is matched with regular expression pattern [pattern], in this way you can set multiple checks and implement simple to highly complicated parsing script easily.
Any URL? I am looking for detailed explanation though yours is good enough.
1

So in searching for a similar problem I came across this post. My task was to parse the full path of a tree node (which is represented as say "root\child\grandchild\greatgrandchild...\currentNode" to pick a level of ancestor to use. While irfanmcsd's answer was elegant, I'm having difficulty geting my arms around setting up the pattern correctly for slashes (and would really like to get better at regular expressions.)

Here was my solution for my particular problem:

    Dim exp As New Regex("\\", RegexOptions.IgnoreCase)
    Dim ancestors() As String

    ancestors = exp.Split(calledFromTreeNode.FullPath)

I now have an array of values to accomplish what I need.

Granted it's not the same problem, but it irfanmcsd's solution helped drive my own. Now I just need get a better understanding of patterns!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.