Jump to content
Sign in to follow this  

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

Share this post


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!

Share this post


Link to post
Share on other sites

Thanks a lot, it works nice. I never knew very well how to use this regular expressions.


When the words fail... music speaks

Share this post


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

Share this post


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

Share this post


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

Share this post


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)

Share this post


Link to post
Share on other sites

Thanks GPinzone & GMK for your help.

@JohnQSmith yes, it's JSON but I don't know how to use the UDF


When the words fail... music speaks

Share this post


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)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • 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
    • By nacerbaaziz
      hello sirs
      i've some questions about StringRegExpReplace i hope you can help me
       
      i tried to make a function that give me the host of the url and other give me the url with out host
      for example i've this link
      https://www.example.com/vb/result.php
      i need the first give me the
      example.com
      and the other give me 
      /vb/result.php
      i find that
      $s_source = "https://www.google.com/vb/index.php" Local $s_Host = StringRegExpReplace($s_Source, '.*://(.*?)/.*', '\1') Local $s_Page = StringRegExpReplace($s_source, '.*://.*?(/.*)', '\1') msgBox(64, $s_Host, $s_Page)  
      but i found some problems i need your help to correct it
      first: when i get the host if the url has www i want to remove it
      second: if the url with out host did not have other things 
      i need the result to be ""
      e.g
      https://www.example.com
      the first i want it
      example.com
      and the second i want it to be ""
      i hope that you can help me
      thanks in advance
    • By iAmNewbe
      I created an application to catch keyboard programmed keys.  Some of the keys open URL's via ShellExecute and then they open in the default browser.

      The problem I am having is that when the browser is opened in this manner 3rd party applications such as Logitech Setpoint for Logitech mouse and keyboards and programs like auto password form filling stop working with the browser.  In the mouse specific situation the Cruise Up and Cruise Down buttons, normally back and forward, do not work. If I open the browser manually via the browsers icon and then press the keyboard buttons to open the web page everything works normally.

      I have two questions:

      1:  Why does 
      ShellExecute("http://www.autoitscript.com") when the browser is not open and then is launched, via the above line, cause third party apps to not be able to interface with the browser?


      2:  What is a better way to launch URL's if not via ShellExecute?


      The application is NOT using #RequireAdmin and is not 64bit.
×
×
  • Create New...