Kyan Posted May 5, 2015 Share Posted May 5, 2015 (edited) Hi, I don't know why this is happening, but better post the code#include <Array.au3> $json = '[{"Id":"2","button":"#random#","status":"ok"},{"Id":"56","button":"#random#","status":"checking"},{"Id":"61","button":"#random#","status":">"},{"Id":"42","button":"#random#",' & _ '"status":">"},{"Id":"43","button":"#random#","status":"ok"},{"Id":"45","button":"#random#","status":"failed"}]' $aJSON = StringRegExp($json, '(?i)\{"Id":"(\d+?)","button":".+?","status":"(?:ok|checking)"\}',3) _ArrayDisplay($aJSON)output:2 56 61expected2 56 43I don't know why SRE is capturing 61 Edited May 5, 2015 by Kyan Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 5, 2015 Moderators Share Posted May 5, 2015 Kyan,Best I can do is to capture the id and the status of each button and then check:#include <Array.au3> $json = '[{"Id":"2","button":"#random#","status":"ok"},{"Id":"56","button":"#random#","status":"checking"},{"Id":"61","button":"#random#","status":">"},{"Id":"42","button":"#random#",' & _ '"status":">"},{"Id":"43","button":"#random#","status":"ok"},{"Id":"45","button":"#random#","status":"failed"}]' $aJSON = StringRegExp($json, '(?U)"Id":"(\d+)".*"status":"(.*)"', 3) ; :"#random#","status":"" _ArrayDisplay($aJSON, "", Default, 8) For $i = UBound($aJSON) - 1 To 0 Step -2 $sStatus = $aJSON[$i] _ArrayDelete($aJSON, $i) Switch $sStatus Case "ok", "checking" ; Do nothing Case Else _ArrayDelete($aJSON, $i - 1) EndSwitch Next _ArrayDisplay($aJSON, "", Default, 8)No doubt an SRE guru will be along shortly with something really clever.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted May 5, 2015 Share Posted May 5, 2015 (edited) #include <Array.au3> $json = '[{"Id":"2","button":"#random#","status":"ok"},{"Id":"56","button":"#random#","status":"checking"},{"Id":"61","button":"#random#","status":">"},{"Id":"42","button":"#random#",' & _ '"status":">"},{"Id":"43","button":"#random#","status":"ok"},{"Id":"45","button":"#random#","status":"failed"}]' $aJSON = StringRegExp($json, '(?i)"Id":"(\d+)[^}]+(?:ok|checking)', 3) _ArrayDisplay($aJSON)Edit : forgot the comment The negated character class [^}]+ will make the search restart at the current position as soon as a } is found Edited May 5, 2015 by mikell Link to comment Share on other sites More sharing options...
Malkey Posted May 5, 2015 Share Posted May 5, 2015 KyanHopefully, the block comment in this script explains the problem you are having with ".+?" in your RE pattern.#include <Array.au3> $json = '[{"Id":"2","button":"#random#","status":"ok"},' & _ '{"Id":"56","button":"#random#","status":"checking"},' & _ '{"Id":"61","button":"#random#","status":">"},' & _ '{"Id":"42","button":"#random#","status":">"},' & _ '{"Id":"43","button":"#random#","status":"ok"},' & _ '{"Id":"45","button":"#random#","status":"failed"}]' $aJSON = StringRegExp($json, '(?i)\{"Id":"(\d+?)","button":"[^:]+:"(?:ok|checking)"\}', 3) #cs $aJSON = StringRegExp($json, '(?i)\{"Id":"(\d+?)","button":".+?","status":"(?:ok|checking)',3) \{"Id":"(\d+?)","button":" matches {"Id":"61","button":" with 61 captured; .+?","status":"(?:ok|checking) means match all characters until the first occurrence of ","status":"(?:ok|checking) is matched. So .+? matches:- #random#","status":">"},' & _ '{"Id":"42","button":"#random#","status":">"},' & _ '{"Id":"43","button":"#random#","status":"ok"} #ce _ArrayDisplay($aJSON) #cs ;Returns:- 2 56 43 #ce Kyan 1 Link to comment Share on other sites More sharing options...
Kyan Posted May 5, 2015 Author Share Posted May 5, 2015 Malkey, so SRE is not delimited by the text you enter? (thought it would be constrained inside the curve brackets "\{\}")So, if it behaves like a inline script is more complex to imagine how it is gonna to behave :|, can this be done with lookahead? Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now