gcue Posted October 12, 2021 Share Posted October 12, 2021 (edited) Hello I am trying to get GMS-600 from this $oHTTP.ResponseText but have not been able to figure out the right syntax. THANK YOU in advance! $txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}' ;$ticket = StringRegExpReplace($txt, '"issueKey":[\w]', "") $ticket = StringRegExpReplace($txt, "issueKey[\w]:", "") Edited October 12, 2021 by gcue Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 12, 2021 Moderators Share Posted October 12, 2021 gcue, This works for me - and will look for any number of capital letters, a dash, and any number of digits at that position: $txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}' $ticket = StringRegExpReplace($txt, '(.*Key":")([A-Z]*-\d*)(",".*)', "$2") ConsoleWrite($ticket & @CRLF) It looks for 3 groups: everything up to the end of the "issueKey" section, the section you want, and then all the rest - returning just the second section, which is the one you want. 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...
gcue Posted October 12, 2021 Author Share Posted October 12, 2021 awesome thank you!!! Link to comment Share on other sites More sharing options...
Zedna Posted October 12, 2021 Share Posted October 12, 2021 (edited) Here is version using _StringBetween(): #Include <String.au3> $txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}' $ticket = StringBetween($txt, '"issueKey":"', '"') ConsoleWrite($ticket & @CRLF) ; wrapper to return string instead of array Func StringBetween($sString, $sStart, $sEnd) $sReturn = _StringBetween($sString, $sStart, $sEnd) If @error Then Return '' Return $sReturn[0] EndFunc Edited October 12, 2021 by Zedna Skysnake 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
markyrocks Posted October 12, 2021 Share Posted October 12, 2021 (edited) this seems to work. #include <Array.au3> $txt = '{"_expands":["participant","status","sla","requestType","serviceDesk"],"issueId":"1301831","issueKey":"GMS-600","requestTypeId":"300","serviceDeskId":"13","createdDate":{"iso8601":"2021-10-12T07:08:17-0700","jira"}}' $ticket = StringRegExp($txt, "[A-Z]{3}-\d+", 1) if IsArray($ticket) Then _ArrayDisplay($ticket) Edited October 12, 2021 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
TheDcoder Posted October 12, 2021 Share Posted October 12, 2021 Kind of surprised that no one has mentioned using a JSON UDF yet. That's the proper way to do it unless you are really sure that you won't need to do anything else with the response. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
Danp2 Posted October 12, 2021 Share Posted October 12, 2021 1 minute ago, TheDcoder said: Kind of surprised that no one has mentioned using a JSON UDF yet. It crossed my mind for a fleeting moment... TheDcoder 1 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
JockoDundee Posted October 13, 2021 Share Posted October 13, 2021 5 hours ago, TheDcoder said: Kind of surprised that no one has mentioned using a JSON UDF yet. What and give up the chance for some tasty RegEx? seadoggie01 and TheDcoder 1 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
seadoggie01 Posted October 13, 2021 Share Posted October 13, 2021 (edited) Use RegEx and forget it, or spend an hour learning Jason JSON parsing? RegEx wins everytime! Edited October 13, 2021 by seadoggie01 TheDcoder, JockoDundee and Skysnake 1 2 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types 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