1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need some more help with RegEx to grab everything between apstrophes.

Discussion in 'General Programming Chat' started by simpleonline1234, Apr 26, 2012.

  1. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    My app needs to Parse the text to grab only the numbers, letters inside the apstrophes as seen below.
    Code:
    challenge : '03AHJ_VusHZDEr-qZYnfmRm4QbevEdYMXPLUibIP-bInEgiAPc0tk4e5MAVntRv_JbvD0q51aJOQp1FZ8RmIaMGt-Te9CSwkZyJhvSK70ZvdOA0AhPJz76t1FhXekXWIuor6YqdVwbqXSFlUSQvi9eL455ojSBkoQW_w'
    My current string for this is the same as above but my regex to get only the information between these apstrophnes doesn't return a results.
    Note that I am trying to get all letters and numbers [a-zA-Z0-9]. My main issue is that the code has random - and _ codes in the challenge.
    How can I configure my Regex to just grab anything inside the apstrophes?
    thanks
    Code:
    Sub RegExGet1()
    
            Dim value As String = "'challenge : '03AHJ_VusHZDEr-qZYnfmRm4QbevEdYMXPLUibIP-bInEgiAPc0tk4e5MAVntRv_JbvD0q51aJOQp1FZ8RmIaMGt-Te9CSwkZyJhvSK70ZvdOA0AhPJz76t1FhXekXWIuor6YqdVwbqXSFlUSQvi9eL455ojSBkoQW_w'"
             Dim m As Match = Regex.Match(ResponseIT.Text, "'challenge : '[a-zA-Z0-9]'", RegexOptions.IgnoreCase)
            If (m.Success) Then
                Dim key As String = m.Groups(1).Value
                KeyIt.Text = (key)
           
            End If
        End Sub
    
     
  2. andee

    andee Regular Member

    Joined:
    Jul 24, 2010
    Messages:
    218
    Likes Received:
    83
    you could always try the getstringinbetween function thats floating around.

    basically is searches for a given string, inbetween two strings that you set. Ive got one floating around somewhere if you need it, I didnt code it though.
     
  3. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    First grab the contents between the apostrophes. Second, remove the non-letter and and non-digit characters.
     
  4. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    Hey Jazzc thanks for the reply..yeah I guess that's kind of my questions what is the RegEx pattern to grab information between apostrophes?. Thanks
     
  5. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,468
    Likes Received:
    10,148
    Code:
    Dim ResultString As String
    Try    
        ResultString = Regex.Match(SubjectString, "challenge : '(.*?)'").Groups(1).Value
    Catch ex As ArgumentException    
        'Syntax error in the regular expression
    End Try
    
    Oh, and don't double post threads in different sections :p
     
  6. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    Sorry Bro..but thank you for the reply Jazzc. Works Great!!