Results 1 to 4 of 4

Thread: [RESOLVED] Looping Regex Match Collection

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Resolved [RESOLVED] Looping Regex Match Collection

    Hi Guys,

    I have my regex setup, which works prefectly:

    code:

    vb.net Code:
    1. Dim testStr As String = "<option value=""18621335"">graham23s</option>"
    2.             Dim rx As New Regex("\<option value=""(\d+)""\>(.+?)\<\/option\>")
    3.  
    4.             MsgBox(rx.Match(testStr).Groups(1).Value)
    5.             MsgBox(rx.Match(testStr).Groups(2).Value)

    When i put it into my own application i have done:

    code:

    vb.net Code:
    1. Dim stringSource As New Regex("\<optionvalue=""(\d+)""\>(.+?)\<\/option\>", RegexOptions.IgnoreCase Or RegexOptions.Singleline)
    2.             Dim stringMatches As MatchCollection = stringSource.Matches(stringClean)
    3.  
    4.             For Each stringsMatch As Match In stringMatches
    5.  
    6.  
    7.  
    8.             Next

    what i am having trouble with is getting the values while in the foreach loop, any help would be appreciated.

    thanks a lot guys

    Graham

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: Looping Regex Match Collection

    solved it! thanks guys

    Graham

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] Looping Regex Match Collection

    vb.net Code:
    1. Dim stringSource As New Regex("\<optionvalue=""(\d+)""\>(.+?)\<\/option\>", RegexOptions.IgnoreCase Or RegexOptions.Singleline)
    2.             Dim stringMatches As MatchCollection = stringSource.Matches(stringClean)
    3.             For Each match As Match In stringMatches
    4.                stringsMatch1 = match.Groups(1).Value
    5.                stringsMatch2 = match.Groups(2).Value
    6.  
    7.  
    8.             Next
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Location
    Scotland
    Posts
    417

    Re: [RESOLVED] Looping Regex Match Collection

    Thanks pradeep! thats better than what i had

    Graham

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width