Alexxander Posted May 26, 2015 Share Posted May 26, 2015 (edited) i have lots of lines like this:Geek - Smarter Shopping 1.1.5Soccer Stars 1.4.3Rock Hero 1.1.3Pinterest 4.6.1Winter Craft 3: Mine Build 1.1.5Flick Shoot 2 1.25 i want to split the name from the version$arr1 = Pinterest @arr2 = 4.6.1 what would the most precise way to do this ?maybe split it when autoit find a word then a number (decimal or integer) what would the regex split command be for a goal like this ? Edited May 26, 2015 by Alexxander Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2015 Moderators Share Posted May 26, 2015 Alexxander,This seems to work quite well:#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" $aRet = StringRegExp($sText, "(?mU)^(.*)([\d.]*)$", 3) _ArrayDisplay($aRet, "", Default, 8)SRE decode:(?mU) - Treat all lines as separate strings - look for shortest match ^ - Start of the line (.*) - Capture all characters up until the next group ([\d.]*) - Capture any group made up of digita and dots until... $ - the end of the lineNo doubt a real guru will be along shortly with a better answer.M23 Alexxander 1 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...
Alexxander Posted May 26, 2015 Author Share Posted May 26, 2015 Melba23Thanks bro, was missing you ,i had not seen you around for a while ... Link to comment Share on other sites More sharing options...
Alexxander Posted May 26, 2015 Author Share Posted May 26, 2015 Alexxander,This seems to work quite well:#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" $aRet = StringRegExp($sText, "(?mU)^(.*)([\d.]*)$", 3) _ArrayDisplay($aRet, "", Default, 8)SRE decode:(?mU) - Treat all lines as separate strings - look for shortest match ^ - Start of the line (.*) - Capture all characters up until the next group ([\d.]*) - Capture any group made up of digita and dots until... $ - the end of the lineNo doubt a real guru will be along shortly with a better answer.M23this did't worked for me when i faced this : Spider-Man Unlimited 1.4.1a any ideas ? Link to comment Share on other sites More sharing options...
iamtheky Posted May 26, 2015 Share Posted May 26, 2015 If there are never going to be spaces in the version then splits should do:#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $aText = stringsplit($sText , @LF , 2) for $i = ubound($aText) - 1 to 0 step - 1 $aLine = stringsplit($aText[$i], " " , 2) $aText[$i] = StringReplace($aText[$i] , $aLine[ubound($aLine) - 1] , "") $Test = $i = ubound($aText) - 1 ? _ArrayAdd($aText , $aLine[ubound($aLine) - 1]) : _ArrayInsert($aText , $i + 1 , $aLine[ubound($aLine) - 1]) next _ArrayDisplay($aText) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2015 Moderators Share Posted May 26, 2015 Alexxander,I hate it when people suddenly produce edge cases - but this one is pretty easy to solve:#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $aRet = StringRegExp($sText, "(?mU)^(.*)([\d.]*\D?)$", 3) _ArrayDisplay($aRet, "", Default, 8)The only change is this:([\d.]*\D?) - Capture any group made up of digits and dots (which might have a trailing non-digit) until...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...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 (edited) Alexxander,Another possible solution...#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $aRet = StringRegExp($sText, "(?m)[^ ]+$", 3) _ArrayDisplay($aRet, "", Default, 8)kylomasedit: Ooops, created another entry in thread instead of edit... Edited May 26, 2015 by kylomas additional info Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 or this...#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $aRet = StringRegExp($sText, "(?m)[\w|\.]+$", 3) _ArrayDisplay($aRet, "", Default, 8) Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted May 26, 2015 Share Posted May 26, 2015 Melba,Your code will fail if an item has no version number$sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Tralala" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a"So you could use$txt2 = StringRegExpReplace($sText, '\h(?=\d+\.)', "#") Msgbox(0,"", $txt2)And then securely StringSplit each item Link to comment Share on other sites More sharing options...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 (edited) mikell - Good catch - mine will fail also! But now we are getting into the semantics of "what is a version number"... Edited May 26, 2015 by kylomas clarification Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Alexxander Posted May 26, 2015 Author Share Posted May 26, 2015 thank you all for responces what do you think about my Modest method ?$file[12] = Spider-Man Unlimited 1.4.1a$split = StringInStr($file[12],".") - 2 ;name + version $name = StringMid($file[12],1,$split) $version = StringMid($file[12],$split + 1,-1) MsgBox(0,0,"'" & $name & "_" & $version & "'") Link to comment Share on other sites More sharing options...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 Alexxander,It's OK if the spacing never changes...consider the following (similar to yours)#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" local $aText = stringsplit($sText,@CRLF,$STR_NOCOUNT+$STR_ENTIRESPLIT) for $i = 0 to ubound($aText) - 1 $aRet = StringRegExp($aText[$i], "(?m)(.+) +(.+)$", 3) if not isarray($aRet) then ConsoleWrite('Product = ' & $aText[$i] & @CRLF) Else ConsoleWrite(stringformat('Product = %-30s Version = %10s', $aRet[0], $aRet[1]) & @CRLF) endif nextkylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted May 26, 2015 Share Posted May 26, 2015 kylomas,Let's assume that the 2 is a version number in "Flick Shoot 2.0" but not in "Flick Shoot 2" Alexxander,Considering the title of this topic, please note that my previous example gives the same result if you just replace # by _ in the expression Link to comment Share on other sites More sharing options...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 mikell - Truly, then the OP can change it to whatever he likes...again "what is a version number"... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted May 26, 2015 Share Posted May 26, 2015 (edited) kylomas,Definitely I'd do it like this for a result in a 2D array#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Tra la la" & @CRLF & _ "Tra la la 2" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $txt2 = StringRegExpReplace($sText, '\h(?=\d+\.)', "#") ;Msgbox(0,"", $txt2) $lines = StringRegExp($txt2, '(?m)(^.*)\R?', 3) $n = UBound($lines) Local $res[$n][2] For $i = 0 to $n - 1 $s = StringSplit($lines[$i], "#") $res[$i][0] = $s[1] $res[$i][1] = ($s[0] = 1) ? "" : $s[2] Next _ArrayDisplay($res)EditA version number should include a dot - otherwise nothing is possible Edited May 26, 2015 by mikell Link to comment Share on other sites More sharing options...
kylomas Posted May 26, 2015 Share Posted May 26, 2015 @mikell - Nice Solution! Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted May 26, 2015 Share Posted May 26, 2015 ThanksIt should work in any case - until the next unexpected requirement Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 26, 2015 Moderators Share Posted May 26, 2015 mikell,My version (I had not seen yours beforehand):#include <Array.au3> $sText = "Geek - Smarter Shopping 1.1.5" & @CRLF & _ "Soccer Stars 1.4.3" & @CRLF & _ "Rock Hero 1.1.3" & @CRLF & _ "Pinterest 4.6.1" & @CRLF & _ "No Version Number" & @CRLF & _ "Winter Craft 3: Mine Build 1.1.5" & @CRLF & _ "Flick Shoot 2 1.25" & @CRLF & _ "Spider-Man Unlimited 1.4.1a" $aRet = StringRegExp($sText, "(?mU)^(.*)([\d.]+\D?)?$", 3) Global $aFinal[UBound($aRet)][2] $iIndex = -1 For $i = 0 To UBound($aRet) - 1 Step 2 $iIndex +=1 $aFinal[$iIndex][0] = $aRet[$i] ConsoleWrite($aRet[$i] & " - " & StringLeft($aRet[$i + 1], 1) & @CRLF) If StringRegExp(StringLeft($aRet[$i + 1], 1), "\d") Then $aFinal[$iIndex][1] = $aRet[$i + 1] Else $i -= 1 EndIf Next ReDim $aFinal[$iIndex][2] _ArrayDisplay($aFinal, $i, Default, 8)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...
Alexxander Posted May 26, 2015 Author Share Posted May 26, 2015 What i like about this forum members , that other forums members does not have is that they are always searching for something to stay busy thank you guys i really love this place , here is where i learned the first line of codeAll respect BinaryBrother 1 Link to comment Share on other sites More sharing options...
mikell Posted May 26, 2015 Share Posted May 26, 2015 Melba,"Spider-Man Unlimited 1.4.1a2"Oy oy oy 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