Zoreal Posted July 6, 2012 Share Posted July 6, 2012 Hello, I'm having some issue matching my string. StringRegExp($MatchArray[$u],'channel":(.*)}',3) The string looks like this... blahblah..."channel":2} I'm attempting to get the contents between the : and } Thank you for any help! Z Link to comment Share on other sites More sharing options...
UEZ Posted July 6, 2012 Share Posted July 6, 2012 You mean the number. Try this StringRegExp($MatchArray[$u], '.*":(d+)}', 3) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2012 Moderators Share Posted July 6, 2012 Zoreal,Flag 3 with StringRegExp returns an array - so you need to access its elements: $sText = 'blahblah..."channel":2}' $aRet = StringRegExp($sText,'channel":(.*)}',3) MsgBox(0, "Return", $aRet[0])Personally I would use StringRegExpReplace to get the string directly: $sText = 'blahblah..."channel":2}' $sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1") MsgBox(0, "Return", $sRet)All clear? 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...
Zoreal Posted July 6, 2012 Author Share Posted July 6, 2012 (edited) You mean the number. Try this StringRegExp($MatchArray[$u], '.*":(d+)}', 3) Br, UEZ Well, in the sample I gave... I'm trying to grab the number 2. It won't necessarily be a number though. Also, I did try the d suggestion - It also failed to get the 2 out. Edited July 6, 2012 by Zoreal Link to comment Share on other sites More sharing options...
Zoreal Posted July 6, 2012 Author Share Posted July 6, 2012 (edited) Zoreal, Flag 3 with StringRegExp returns an array - so you need to access its elements: $sText = 'blahblah..."channel":2}' $aRet = StringRegExp($sText,'channel":(.*)}',3) MsgBox(0, "Return", $aRet[0]) Personally I would use StringRegExpReplace to get the string directly: $sText = 'blahblah..."channel":2}' $sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1") MsgBox(0, "Return", $sRet) All clear? M23 I'm using the StringRegExp to extract 1 piece - Given the dataset I'm using it on, it cannot return more the 1 value. Therefore...I'm using it as something like $String = $SomeOtherVarsBeingPlacedHere & Chr(9) & _ArrayToString(StringRegExp($MatchArray[$u],'channel":(d*)}',3)) All I need is for the StringRegExp to return its $Array[0]=2 Edited July 6, 2012 by Zoreal Link to comment Share on other sites More sharing options...
UEZ Posted July 6, 2012 Share Posted July 6, 2012 (edited) As Melba suggested you can use StringRegExpReplace() to strip out the information you need! $String = $SomeOtherVarsBeingPlacedHere & Chr(9) & StringRegExpReplace($MatchArray[$u],'.*channel":(.*)}', "$1") d means any digit (0-9) and if it is not a number then using d makes no sense. Br, UEZ Edited July 6, 2012 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 6, 2012 Moderators Share Posted July 6, 2012 Zoreal,StringRegExp will either return True/False or an array depending on the flag - you cannot get the matched group directly. That is why I would go for the StringRegExpReplace option. 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...
Zoreal Posted July 6, 2012 Author Share Posted July 6, 2012 Thank you both! Link to comment Share on other sites More sharing options...
Zoreal Posted July 11, 2012 Author Share Posted July 11, 2012 Zoreal, Flag 3 with StringRegExp returns an array - so you need to access its elements: $sText = 'blahblah..."channel":2}' $aRet = StringRegExp($sText,'channel":(.*)}',3) MsgBox(0, "Return", $aRet[0]) Personally I would use StringRegExpReplace to get the string directly: $sText = 'blahblah..."channel":2}' $sRet = StringRegExpReplace($sText,'.*channel":(.*)}', "$1") MsgBox(0, "Return", $sRet) All clear? M23 I had a change in input for this - The string now exists sometimes in each of the forms below. "stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":2 "stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}] Notice the '}]' sometimes is appended after the number... How can I structure the StringRegExpReplace to match only the channel's value? StringRegExpReplace($MatchArray[$u],'channel":(/d*?)}?','$1') This is what I came up with - Not working though Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 11, 2012 Moderators Share Posted July 11, 2012 Zoreal, This works for me: $sText_1 = '"stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":27' $sText_2 = '"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":29}]' $sExtract_1 = StringRegExpReplace($sText_1, '(?i).*channel":(d*)}?.*', "$1") MsgBox(0, "String 1", $sText_1 & @CRLF & @CRLF & $sExtract_1) $sExtract_2 = StringRegExpReplace($sText_2, '(?i).*channel":(d*)}?.*', "$1") MsgBox(0, "String 2", $sText_2 & @CRLF & @CRLF & $sExtract_2) 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...
UEZ Posted July 11, 2012 Share Posted July 11, 2012 Or this way: #include <Array.au3> $sText = '"stop":27426,"category":"Customer satisfaction","start":26606,"phrase":"poor customer service","confidence":23,"channel":27' & @CRLF & _ '"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":29}]' $aResult = StringRegExp($sText, '(?i)channel":(.*)b', 3) _ArrayDisplay($aResult) Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
AZJIO Posted July 11, 2012 Share Posted July 11, 2012 (edited) $test='"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}]' $pos=StringInStr($test, 'channel":') $test=Number(StringTrimLeft($test, $pos+8)) MsgBox(0, 'Yes?', $test)$test='"stop":3516,"category":"Script Compliance","start":2826,"phrase":"thank you for calling","confidence":26,"channel":2}]' $test=StringRegExpReplace($test, '(?i).*?channel":(d+).*', '1') MsgBox(0, 'Yes?', $test) Edited July 11, 2012 by AZJIO My other projects or all 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