Rex Posted April 30, 2016 Share Posted April 30, 2016 (edited) Hi I have a string like this User IDs: User001, User002, User0003, user0004 And I want to return all user ID's using stringregexp, but I can only get it to return the last string eg. user0004 _ArrayDisplay(StringRegExp($String, '(user\d{1,})', 1)) I have tried to uses \K \1 (?1) but none of them helped, I can only get it to return the last string I have been reading the help file forth and back a million times now, I goggled stringregexp and still I can't get it to return all strings. Could it be that there is a stringregexp expert in here that could help me get the result I want? Cheers /Rex Edited May 1, 2016 by Rex Link to comment Share on other sites More sharing options...
MichaelHB Posted April 30, 2016 Share Posted April 30, 2016 @Rex Caseless and global! #include <array.au3> $String = 'User IDs: User001, User002, User0003, user0004' _ArrayDisplay(StringRegExp($String, '(?i)user\d{1,}', 3)) Exit Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 30, 2016 Moderators Share Posted April 30, 2016 (edited) Rex, Set the flag to 3 ($STR_REGEXPARRAYGLOBALMATCH) rather than 1 and make the match case-insensitive: #include <Array.au3> $sString = "User IDs: User001, User002, User0003, user0004" $aRet = StringRegExp($sString, "(?i)(user\d{1,})", 3) _ArrayDisplay($aRet, "All", Default, 8) M23 Edit: Good for MichaelHB! Edited April 30, 2016 by Melba23 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...
Rex Posted April 30, 2016 Author Share Posted April 30, 2016 Cool The caseless is not necessary, it was a typo from my side, forgot to upper the last U in my test string This works like a charm on my test string, but I can't get it to work on actual string :/ witch of course I should had posted instead of the test string We get this result from our server. {"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]} and it's the user list path I'm trying to get using regexp _ArrayDisplay(StringRegExp($string, '.*"(.*\.lst).*', 1)) Cheers /Rex Link to comment Share on other sites More sharing options...
MichaelHB Posted April 30, 2016 Share Posted April 30, 2016 Let's use Melba's example (its more organized than mine ). #include <Array.au3> $sString = '{"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]}' $aRet = StringRegExp($sString, '(?i)"path":"(.*?)"}]', 3) _ArrayDisplay($aRet, "All", Default, 8) Exit Is this the result that you want? Link to comment Share on other sites More sharing options...
Rex Posted April 30, 2016 Author Share Posted April 30, 2016 @MichaelHB Damn, that's nice that's exactly what I was trying to get It seems that the problem was that I was checking for ".lst" but I shouldn't. Thx so much, I had ben struggling with that for 2-3 hours last night - until I gave up and went to bed. Cheers /Rex Link to comment Share on other sites More sharing options...
MichaelHB Posted April 30, 2016 Share Posted April 30, 2016 Glad to help. Link to comment Share on other sites More sharing options...
mikell Posted April 30, 2016 Share Posted April 30, 2016 59 minutes ago, Rex said: It seems that the problem was that I was checking for ".lst" but I shouldn't. I don't agree $aRet = StringRegExp($sString, '(\w+)\.lst', 3) Link to comment Share on other sites More sharing options...
iamtheky Posted April 30, 2016 Share Posted April 30, 2016 (edited) i don't not agree, but for different reasons $aRet = StringRegExp($sString, '(user\d+?)\.', 3) $sString = '{"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]}' $sRet = "" $i = 0 Do $i += 1 $sRet &= stringmid($sString , stringinstr($sString , "user" , 1 , $i) , stringinstr($sString , ".lst" , 1 , $i) - stringinstr($sString , "user" , 1 , $i)) & @CRLF Until stringinstr($sRet , @CRLF & @CRLF) msgbox(0, $i , stringtrimright($sRet , 4)) Edited May 1, 2016 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
alien4u Posted May 1, 2016 Share Posted May 1, 2016 Just for fun: #include <Array.au3> #include <String.au3> $sString = '{"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]}' $users = _StringBetween($sString,"us",".lst") For $i = 0 To UBound($users) -1 $users[$i] = StringReplace($users[$i],"er","user") Next _ArrayDisplay($users) Regards Link to comment Share on other sites More sharing options...
Rex Posted May 1, 2016 Author Share Posted May 1, 2016 On 30/4/2016 at 6:46 PM, mikell said: I don't agree $aRet = StringRegExp($sString, '(\w+)\.lst', 3) Yes, but with my code - the .lst was the problem Cheers /Rex Link to comment Share on other sites More sharing options...
Rex Posted May 1, 2016 Author Share Posted May 1, 2016 (edited) 20 hours ago, iamtheky said: i don't not agree, but for different reasons $aRet = StringRegExp($sString, '(user\d+?)\.', 3) $sString = '{"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]}' $sRet = "" $i = 0 Do $i += 1 $sRet &= stringmid($sString , stringinstr($sString , "user" , 1 , $i) , stringinstr($sString , ".lst" , 1 , $i) - stringinstr($sString , "user" , 1 , $i)) & @CRLF Until stringinstr($sRet , @CRLF & @CRLF) msgbox(0, $i , stringtrimright($sRet , 4)) Yes, but for the way I had made my code .lst was the problem Always nice to see another way to get the same result Cheers /Rex Edited May 1, 2016 by Rex Link to comment Share on other sites More sharing options...
Rex Posted May 1, 2016 Author Share Posted May 1, 2016 11 hours ago, alien4u said: Just for fun: #include <Array.au3> #include <String.au3> $sString = '{"Date":"20160422","Flow":[{"Ordres":[{"Ordre":2985484,"path":"\\emp\work\ordres\2985484.log"},{"Ordre":2954269,"path":"\\emp\work\ordres\2954269.log"},{"Ordre":2986125,"path":"\\emp\work\ordres\2986125.log"}],"ended":"true"}],"lists":[{"list":[{"path":"\\emp\work\user582.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user580.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user492.lst"}],"ended":"true"},{"list":[{"path":"\\emp\work\user495.lst"}],"ended":"true"}]}' $users = _StringBetween($sString,"us",".lst") For $i = 0 To UBound($users) -1 $users[$i] = StringReplace($users[$i],"er","user") Next _ArrayDisplay($users) Regards Cool, It's always to see other ways to get the same result Cheers /Rex 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