dcsimg
Results 1 to 5 of 5

Thread: [Help] Loop through results [RegeX]

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    [Help] Loop through results [RegeX]

    hi,

    I have a small issue with my code and i am looking for a bit of guidance.

    I am new to using RegeX but i have managed to piece together what i need and so far it's working nicely but the only issue i have is that i can't figure out how to loop my result, i am not sure if i am over thinking the problem or what but here it is.

    I load a page source into a textbox then i use RegeX to find a string and then get me the results.
    Code:
            Dim findString = TextBox1.Text
            Dim match = Regex.Match(findString, "(?<=foocwy.addImage\(')(.*?)(?=','front','(.+)')", RegexOptions.IgnoreCase)
            Dim x = match.Groups(1).Value
            Dim y = match.Groups(2).Value
    
            ListBox2.Items.Add(x & y]
    The line i am getting is "foocwy.addImage('acw','back','1431935595/jc001/acw/back');"

    Where 'acw' is X and '1431935595/jc001/acw/back' is Y

    There are multiples of this line and the number is different for each page i need to get it from but just working from this one "page" there are lets say 20 of these lines but all 20 have different X and Y values.

    Any suggestions on how i can use the current code i have to loop through the textbox, find each one of these lines and add them to the listbox.
    Last edited by lynx2011; Mar 26th, 2017 at 04:51 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,498

    Re: [Help] Loop through results [RegeX]

    Code:
    Imports System.Text.RegularExpressions
    Code:
    Dim findString = TextBox1.Text
    Dim rx As New Regex("(?<=foocwy.addImage\(')(.*?)(?=','front','(.+)')", RegexOptions.IgnoreCase)
    Dim matches As MatchCollection = rx.Matches(findString)
    For Each m As Match In matches
        Dim x = m.Groups(1).Value
        Dim y = m.Groups(2).Value
        ListBox2.Items.Add(x & y)
    Next

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    Thumbs up Re: [Help] Loop through results [RegeX]

    Quote Originally Posted by .paul. View Post
    Code:
    Imports System.Text.RegularExpressions
    Code:
    Dim findString = TextBox1.Text
    Dim rx As New Regex("(?<=foocwy.addImage\(')(.*?)(?=','front','(.+)')", RegexOptions.IgnoreCase)
    Dim matches As MatchCollection = rx.Matches(findString)
    For Each m As Match In matches
        Dim x = m.Groups(1).Value
        Dim y = m.Groups(2).Value
        ListBox2.Items.Add(x & y)
    Next
    Awesome!

    Thank you for that!!

    I was currently reading and following the MatchCollection class documentation from MSDN (https://msdn.microsoft.com/en-us/lib...=vs.110).aspx) and i was trying to piece together what was needed.

    Comparing your code to what i had i'm happy that i was not far off the completed method!

    Again, thank you for that!!

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    22,498

    Re: [Help] Loop through results [RegeX]

    What you were using was singular as opposed to multiple

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2011
    Posts
    35

    Re: [Help] Loop through results [RegeX]

    Yeah when i started to read over the MSDN document i noticed that i was not using the collection correctly. Cheers!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width