Jump to content
Sign in to follow this  


Recommended Posts


Ive got this function Im using to parse some text

Func _Get_List($aParams)
    $sList_URL = $aParams[0] & "?list=1" & "&token=" & $aParams[1]
    $temp = _StringBetween(StringRegExpReplace(BinaryToString(InetRead($sList_URL, 1)), "(\s)", ""), "[[", "]]")
    $aList = StringSplit($temp[0], "],[", 3);<<<<<<< This line
    Local $aFinalList[19][UBound($aList)]
    For $i = 0 To UBound($aFinalList, 2) - 1
        $atemp = StringSplit($aList[$i], ",", 2)
        For $j = 0 To 18
            $aFinalList[$j][$i] = $atemp[$j]
    Return $aFinalList

The problem is with an array returned from _StringBetween(), (commented in code above) where It only works for me if I use $temp[0], but will not work for someone else unless they use $temp[1], which gives me an array out of bounds error.

The array is created with this line

$temp = _StringBetween(StringRegExpReplace(BinaryToString(InetRead($sList_URL, 1)), "(\s)", ""), "[[", "]]")

and the BinaryToString(InetRead($sList_URL, 1)) returns some text, here is an example of the string it might return JSON format I think

{"build":19648,"label": [
,"torrents": [

,"torrentc": "1360124475"}

Im just wondering if it could be something to do with my lacklustre attempt at the regex.

I'd be delighted if a keen eye could give me hint at my problem.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post

Link to post
Share on other sites

Try this:

Local $s = FileRead("json.txt")
Local $temp = StringRegExp($s, '(?m)^\[([^\]]*)\](?>[,\]]$)', 3)

Here, json.txt is a copy/paste of your example, so $s is identical to your BinaryToString(InetRead($sList_URL, 1))

It may not be 100% failproof as it will break if ever the line format changes, but that may be unlikely to occur spontaneously.

BTW, you shouldn't use function pipelining, as it gains very little and makes you vulnerable to error(s), should some inner function fail.

While it's fairly common to pipeline functions that aren't subject to failure, things like InetRead _are_ open to errors and should have a statement fully devoted for them.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post

Link to post
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
Sign in to follow this