Jump to content

About unordered, ever-changing cookies and my regex pattern?


 Share

Recommended Posts

Is my regex pattern I wrote compatible for this?

(\w+)=([a-z%0-9A-Z]+)[^;]*

It works fine for now but i have doubts about my pattern, I wonder if my my regex pattern will cause problems later?

Global $Cookie[4] = ["Cookie: CookieCode001=a%3A4%3A%7Bi%3A0%%3A0%3B%7D; PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7", _
        "Cookie: PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7; CookieCode002=b%3A4%3A%7Bi%3A0%%3A0%3B%7D", _
        "Cookie: PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7; CookieCode003=c%3A4%3A%7Bi%3A0%%3A0%3B%7D", _
        "Cookie: CookieCode004=d%3A4%3A%7Bi%3A0%%3A0%3B%7D; PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7"]

For $i = 0 To 3
    $CookieRegExp = StringRegExp($Cookie[$i], '(\w+)=([a-z%0-9A-Z]+)[^;]*', 3)
    If IsArray($CookieRegExp) Then
        ConsoleWrite("Cookies : " & $CookieRegExp[0] & "=" & $CookieRegExp[1] & "; " & $CookieRegExp[2] & "=" & $CookieRegExp[3] & @CRLF)
    EndIf
Next

Do you have alternative suggestions for this?

Link to comment
Share on other sites

Sometimes there is only PHPSESSID= in the cookie. 

so this line gives an error :(
If IsArray($CookieRegExp) Then
        ConsoleWrite("Cookies : " & $CookieRegExp[0] & "=" & $CookieRegExp[1] & "; " & $CookieRegExp[2] & "=" & $CookieRegExp[3] & @CRLF)

Global $Cookie[4] = ["Cookie: PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7", _
        "Cookie: PHPSESSID=cq91bbm6frma73olklircu2rc2", _
        "Cookie: PHPSESSID=orju6tvclk878bsdp8l3uo9ri2", _
        "Cookie: PHPSESSID=ppmgeudm7cdtnsk18fevp49743"]

For $i = 0 To 3
    $CookieRegExp = StringRegExp($Cookie[$i], '(\w+)=([a-z%0-9A-Z]+)[^;]*', 3)
    ;if my cookies are PHPSESSID and CookieCode
    If IsArray($CookieRegExp) Then
        ConsoleWrite("Cookies : " & $CookieRegExp[0] & "=" & $CookieRegExp[1] & "; " & $CookieRegExp[2] & "=" & $CookieRegExp[3] & @CRLF)
    Else
        ;else if only PHPSESSID
        $PHPSESSIDRegExpRep = StringRegExpReplace($Cookie[$i], '(?s).*PHPSESSID=(\w+).*', "$1")
        ConsoleWrite("Cookies : " & $PHPSESSIDRegExpRep & @CRLF)
    EndIf
Next

 

Link to comment
Share on other sites

#Include <Array.au3>

Global $Cookie[4] = ["Cookie: CookieCode001=a%3A4%3A%7Bi%3A0%%3A0%3B%7D; PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7", _
        "Cookie: PHPSESSID=aaq4rde1ir38ei0bpmdr2hq2b7; CookieCode002=b%3A4%3A%7Bi%3A0%%3A0%3B%7D", _
        "Cookie: PHPSESSID=orju6tvclk878bsdp8l3uo9ri2", _
        "Cookie: PHPSESSID=ppmgeudm7cdtnsk18fevp49743"]

For $i = 0 To 3
    $CookieRegExp = StringRegExp($Cookie[$i], '(\w+)=([a-z%0-9A-Z]+(?:; )?)', 3)
    If IsArray($CookieRegExp) Then
; _ArrayDisplay($CookieRegExp)
        $txt = "" 
         For $j = 0 To UBound($CookieRegExp)-1 step 2
            $txt &= $CookieRegExp[$j] & "=" & $CookieRegExp[$j+1]
        Next
        ConsoleWrite("Cookies : " & $txt & @CRLF)
    EndIf
Next

Edit
Doubts, you still have ?

Edited by mikell
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...