Jump to content

Recommended Posts

Can some expert with regular expression help me to obtain expected data from a string like that:

"scans": {

"CLEAN MX": {"detected": false, "result": "clean site"},

"TrendMicro": {"detected": false, "result": "clean site"},

"Yandex Safebrowsing": {"detected": false, "result": "clean site"},

"Phishtank": {"detected": false, "result": "clean site"},

"MalwareDomainList": {"detected": false, "result": "clean site"},

"VX Vault": {"detected": false, "result": "clean site"},

"SCUMWARE.org": {"detected": false, "result": "clean site"},

"Google Safebrowsing": {"detected": false, "result": "clean site"},

"Malc0de Database": {"detected": false, "result": "clean site"},

"SpyEyeTracker": {"detected": false, "result": "clean site"},

"BitDefender": {"detected": false, "result": "clean site"},

"Opera": {"detected": false, "result": "clean site"},

"ParetoLogic": {"detected": false, "result": "clean site"},

"Avira": {"detected": false, "result": "clean site"},

"URLQuery": {"detected": false, "result": "unrated site"},

"G-Data": {"detected": false, "result": "clean site"},

"Wepawet": {"detected": false, "result": "unrated site"},

"ZeusTracker": {"detected": false, "result": "clean site"}

}

What I try to get is the name, detected & result. Something like:

CLEAN MX false clean site

Any idea?

When the words fail... music speaks
Link to post
Share on other sites

I'm not a pro, but here how i would have made it:

#Include <Array.au3>
#Include <String.au3>
$str = '"scans": {' & _
'"CLEAN MX": {"detected": false, "result": "clean site"},' & _
'"TrendMicro": {"detected": false, "result": "clean site"},' & _
'"Yandex Safebrowsing": {"detected": false, "result": "clean site"},' & _
'"Phishtank": {"detected": false, "result": "clean site"},' & _
'"MalwareDomainList": {"detected": false, "result": "clean site"},' & _
'"VX Vault": {"detected": false, "result": "clean site"},' & _
'"SCUMWARE.org": {"detected": false, "result": "clean site"},' & _
'"Google Safebrowsing": {"detected": false, "result": "clean site"},' & _
'"Malc0de Database": {"detected": false, "result": "clean site"},' & _
'"SpyEyeTracker": {"detected": false, "result": "clean site"},' & _
'"BitDefender": {"detected": false, "result": "clean site"},' & _
'"Opera": {"detected": false, "result": "clean site"},' & _
'"ParetoLogic": {"detected": false, "result": "clean site"},' & _
'"Avira": {"detected": false, "result": "clean site"},' & _
'"URLQuery": {"detected": false, "result": "unrated site"},' & _
'"G-Data": {"detected": false, "result": "clean site"},' & _
'"Wepawet": {"detected": false, "result": "unrated site"},' & _
'"ZeusTracker": {"detected": false, "result": "clean site"}' & _
'}'

$str = StringRegExp($str, '"scans": {(.*)}', 3)
$str = $str[0]
$reg = StringRegExp($str, '"(.*?)": {".*?": (.*?), ".*?": "(.*?)"}', 3)
$ub = UBound($reg)
ConsoleWrite($ub & @CRLF)
Global $result[1][3] = [[0, "", ""]]
For $i = 0 To $ub - 1 Step +3
ReDim $result[$result[0][0] + 2][3]
$result[0][0] += 1
$result[$result[0][0]][0] = $reg[$i]
$result[$result[0][0]][1] = $reg[$i + 1]
$result[$result[0][0]][2] = $reg[$i + 2]
Next
_ArrayDisplay($result)

Me too, i'm waiting for pros to show us some better ways!

Link to post
Share on other sites

Instead of using

.*?

you can use

[^"]*

which is easier on the regex engine because it doesn't need to backtrack.

EDIT: except for the boolean that isn't in quotes. In that case, just use [a-z]*

EDIT 2: Now that I look at it, there's no reason to use regex for the "detected," and "result" text.

$reg = StringRegExp($str, '"([^"]*)": {"detected": ([a-z]*), "result": "([^"]*)"}', 3)
Edited by GPinzone
Gerard J. Pinzonegpinzone AT yahoo.com
Link to post
Share on other sites

Here's my take on it:

#include <Array.au3>
$sString = '"scans": {' & @CRLF & _
'"CLEAN MX": {"detected": false, "result": "clean site"},' & @CRLF & _
'"TrendMicro": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Yandex Safebrowsing": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Phishtank": {"detected": false, "result": "clean site"},' & @CRLF & _
'"MalwareDomainList": {"detected": false, "result": "clean site"},' & @CRLF & _
'"VX Vault": {"detected": false, "result": "clean site"},' & @CRLF & _
'"SCUMWARE.org": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Google Safebrowsing": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Malc0de Database": {"detected": false, "result": "clean site"},' & @CRLF & _
'"SpyEyeTracker": {"detected": false, "result": "clean site"},' & @CRLF & _
'"BitDefender": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Opera": {"detected": false, "result": "clean site"},' & @CRLF & _
'"ParetoLogic": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Avira": {"detected": false, "result": "clean site"},' & @CRLF & _
'"URLQuery": {"detected": false, "result": "unrated site"},' & @CRLF & _
'"G-Data": {"detected": false, "result": "clean site"},' & @CRLF & _
'"Wepawet": {"detected": false, "result": "unrated site"},' & @CRLF & _
'"ZeusTracker": {"detected": false, "result": "clean site"}' & @CRLF & _
'}'
Local $iOffset = 1
Local $asArray[1][3], $asTemp
$iCount = 1
While 1
    $asTemp = StringRegExp($sString, '"([^"]*)": {"detected": ([a-z]*), "result": "([^"]*)"}', 1, $iOffset)
    If @error = 0 Then
        $iOffset = @extended
    Else
        ExitLoop
    EndIf
    ReDim $asArray[$iCount][3]
    For $i = 0 To UBound($asTemp) - 1
        $asArray[$iCount - 1][$i] = $asTemp[$i]
    Next
    $iCount += 1
WEnd
_ArrayDisplay($asArray)

Edited by GMK
Link to post
Share on other sites

Instead of using

.*?

you can use

[^"]*

which is easier on the regex engine because it doesn't need to backtrack.

Hang on, doesnt regex use FSA (Finite State Automata) algorithm to build the search tree and process the input? why does it need to backtrack?

ongoing projects:-firestorm: Largescale P2P Social NetworkCompleted Autoit Programs/Scripts: Variable Pickler | Networked Streaming Audio (in pure autoIT) | firenet p2p web messenger | Proxy Checker | Dynamic Execute() Code Generator | P2P UDF | Graph Theory Proof of Concept - Breadth First search

Link to post
Share on other sites

Regexp engines are either DFA (deterministic finete-state automaton) or NFA (non-DFA). PCRE includes both engines internally but only the NFA is accessible by means of StringRegExp[Replace].

A DFA never backtracks, contrary to the (our) NFA.

Backtracking is most important when quantifiers appear (+, *, {n, p}) with or without greediness, where almost infinite loops can be triggered.

Hopefully, PCRE is very advanced and embarks a large number of optimizations to detect and avoid uselessly long backtracking.

Edited by jchd

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)

Link to post
Share on other sites

BTW using JSON UDF for such simple task would be overkill IMHO.

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)

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By vinnyMS
      #Include <Array.au3> #include <Constants.au3> $s = FileRead("2.txt") Local $w = StringRegExp($s, '(?is)(\b\w+\b)(?!.*\b\1\b)', 3) _ArrayColInsert($w, 1) For $i = 0 to UBound($w)-1 StringRegExpReplace($s, '(?i)\b' & $w[$i][0] & '\b', $w[$i][0]) $w[$i][1] = @extended Next _ArraySort($w, 1, 0, 0, 1) _ArrayDisplay($w) i have this script that returns 3 columns  
       
      i need to copy the  Col 0 and Col 1 as text to paste on notepad or excel
      you will have to create a "copy" button if possible
      array.au3 2.txt
    • By Jahar
      Hi,
      I am new to Autoit, Kindly guide me. I wanted to send a message with HTTP/GET to the URL https://ghsff.it/. How to do so?
    • By HariKara
      I have a script that seems to launch perfectly fine with IECreate, however, I want to launch the Browser and a specific URL with the RunAs command. I fairly new to AutoIT and wanted to know if someone can point me in the right direction.
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = _IECreate($sURL)
      The above launches the website correctly with the correct URL, however, I have tried the below and this fails to load and browser?
      #include <AutoItConstants.au3>
      ;========================
      $oSleep = "200"
      Local $surl = "http://somewebsite.com/DODA/admin/job.aspx"
      Local $oIE = RunAs($args("username"), $args("domain"), $args("logonpassword"), "", "C:\Program Files (x86)\Internet Explorer\iexplore.exe http://somewebsite.com/DODA/admin/job.aspx")
      _IELoadWait($oIE)
       
      I get the following error back?
      --> IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
      --> IE.au3 T3.0-2 Error from function _IEGetObjById, $_IESTATUS_InvalidDataType
    • By nacerbaaziz
      hello sirs
      please i want to use the WinHttp to get the google drive file title using the api
      i searched in the forom but i didn't found any Google drive api UDF
      for that i liked to ask you for that
      i had read the google drive api documentation but i couldn't do it
      please help me
      here is the api doc
      note i've got the apikey and i have the file id
      what i want is to get the title of the file (the file name)
      because i want to download the files from the google drive using the autoit
      please help me for that
      am sorry because i didn't gave you any example or what i tried but all what tried was  failed
      thanks in advance
×
×
  • Create New...