Rex Posted March 6, 2015 Share Posted March 6, 2015 Hi I'm trying to split this sting "The.Last-Stalker-Lars-Ole.Kepler" with regexp I need it to be splitted like this "The.Last-Stalker" "Lars-Ole.Kepler" I have tried with this (?i)(.+)-(.+), and with this (?i)(.[^-]+)-(.+) and a couple other types like that, but it splits on either the one side or the other side of my expression Of course the string can change, all that i know for sure about the string is that it contains at least one "-" and the string should be splitted in to two as above. Any one that could help me out, or point me in the correct direction of how to do this. Cheers /Rex Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted March 6, 2015 Moderators Share Posted March 6, 2015 (edited) Rex,The problem will be to clearly define the "-" on which to split the string - the problem is trivial if you have only the one but a unique solution is probably not possible when there are several such characters as in your example. Can you be a bit more precise in defining where the split point occurs? M23 Edited March 6, 2015 by Melba23 Wrong button, too soon! 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...
TheDcoder Posted March 6, 2015 Share Posted March 6, 2015 This (Regular Expressions: The Complete Tutorial) might be useful for future reference 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...
Rex Posted March 6, 2015 Author Share Posted March 6, 2015 @Melba23 Yea I was affright of that how ever i know that the string continues like this "Unknown-string".BookRead-2015 And yes i should had posted that in my first tread, sry for that also I should had postede the entire regexp witch is (?i)(.+)-(.+).BookRead-2015 @TheDcoder I have read the Tut several times, but didn't seem to find a solution in it Cheers /Rex Link to comment Share on other sites More sharing options...
jguinch Posted March 6, 2015 Share Posted March 6, 2015 Well, not sure to really understand... You shoud give more examples with the expected result. You can still try with this : #Include <Array.au3> $sString = "The.Last-Stalker-Lars-Ole.Kepler" $aResult = StringRegExp($sString, "(?i)([a-z.]+-[a-z.]+)", 3) _ArrayDisplay($aResult) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
zalomalo Posted March 6, 2015 Share Posted March 6, 2015 (edited) /Rex I have been the other day learning and fighting with RegularExpressions because i thought was an improvement to my program strings treatament. After some sort of hard-hell learningcurve i reached to take that i needed. Then i realised (plus a bit dangerous of recursive loops, and long implement time) that the performance was worse than before with some snnipets i had native-Autoit based. So i throwed all RegExp code to the trash (i know there are times can be the best/only option), and i dont think i´ll retake it again because by now i managed to reach without them. Its too hard to me, with no speed win. If you are interested in alternative way to regexp, i could help you. Edited March 7, 2015 by zalomalo My english shucks, i know it. Link to comment Share on other sites More sharing options...
Rex Posted March 7, 2015 Author Share Posted March 7, 2015 @zalomalo Thx for the offer, any way this can be done, is welcome Cheers /Rex Link to comment Share on other sites More sharing options...
mikell Posted March 7, 2015 Share Posted March 7, 2015 On a string like this "one.two-three-four-five.six" if the results may be "one.two" "one.two-three" "one.two-three-four" "one.two-three-four-five" Then unless you introduce some more restrictions/requirements as Melba suggested, it will not be possible to find a working generic regular expression simply because regex can't guess the expected result Link to comment Share on other sites More sharing options...
TheDcoder Posted March 7, 2015 Share Posted March 7, 2015 @Rex Sorry for for late reply but you can learn regex from this (Expresso) tool, It also has a regex builder ! 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...
Rex Posted March 7, 2015 Author Share Posted March 7, 2015 On a string like this "one.two-three-four-five.six" if the results may be "one.two" "one.two-three" "one.two-three-four" "one.two-three-four-five" Then unless you introduce some more restrictions/requirements as Melba suggested, it will not be possible to find a working generic regular expression simply because regex can't guess the expected result I know, but thats all the info I have - that also why I wrote Regexp Headach Cheers /Rex Link to comment Share on other sites More sharing options...
Rex Posted March 7, 2015 Author Share Posted March 7, 2015 @Rex Sorry for for late reply but you can learn regex from this (Expresso) tool, It also has a regex builder ! Wauuuu that so coool, I will play with it later, thx so much Cheers /Rex Link to comment Share on other sites More sharing options...
TheDcoder Posted March 7, 2015 Share Posted March 7, 2015 @Rex Welcome 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...
kylomas Posted March 7, 2015 Share Posted March 7, 2015 Rex, Is the form of the string you want to capture always the same, Xn.Xn-Xn or Xn-Xn.Xn ? kylomas 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...
Rex Posted March 7, 2015 Author Share Posted March 7, 2015 Rex, Is the form of the string you want to capture always the same, Xn.Xn-Xn or Xn-Xn.Xn ? kylomas The string will always contain one "-", thats all I know for shure :/ /Rex Link to comment Share on other sites More sharing options...
zalomalo Posted March 7, 2015 Share Posted March 7, 2015 (edited) RegExp are abstract operations with strings, and yo dont have a trouble because RegExp or programming. You have a trouble extricly logic. The information you know is not enought to success with a priori rule/algorithm. You would need Artificial Intelligence here. If the source string just have one '-', the operation is trivial. If have more than one, and you dont know if are in the 1st substring or 2th; you lack of info, like some sort of dictionary that helps in knowing more data. Edited March 7, 2015 by zalomalo My english shucks, i know it. Link to comment Share on other sites More sharing options...
kylomas Posted March 7, 2015 Share Posted March 7, 2015 Can you post several lines of the data and what your expected results are? 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...
zalomalo Posted March 7, 2015 Share Posted March 7, 2015 (edited) all that i know for sure about the string is that it contains at least one "-" and the string should be splitted in to two To see several particular examples doesnt help isolating the trouble, but confusing. Analyzing and synthesizing the problem: You must split a string in two; the separator is '-'. The separator is present allways once. But, '-' can be present more times as not a separator. Hence, when you have just one '-', the operation is inmediate. When you get '-' more times than one, you cant know witch one is the separator. You need deeper stated, with no other data '-' is not a valid separator in any case. I insist, its a logic trouble. Edited March 8, 2015 by zalomalo My english shucks, i know it. Link to comment Share on other sites More sharing options...
jguinch Posted March 7, 2015 Share Posted March 7, 2015 What about #5 ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
kylomas Posted March 7, 2015 Share Posted March 7, 2015 zalomalo, I insist, its a logic trouble. Relax, just making sure all the bases are covered... 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 March 7, 2015 Share Posted March 7, 2015 (edited) And what about #8 , along with its extremely positive continuation #10 ? Edit : Edited March 7, 2015 by mikell 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