TheAutomator Posted July 26, 2017 Posted July 26, 2017 Can anyone tell me why this isn't working?.. #include <array.au3> $regexp = StringRegExp("test 'a b c'", "'([^']|'')*'|\S+", 3) _ArrayDisplay($regexp) trying to split this "test 'a b c' 'some other '' test'' ...'" into: 0: test 1: 'a b c' 2: ... but it gives me: 0: test 1: c nacerbaaziz 1 Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
TheAutomator Posted July 26, 2017 Author Posted July 26, 2017 (edited) 12 minutes ago, Malkey said: This matches one "not single quote" character. [^'] yes but it's in a (group)* so it matches everything between single quotes that is not a quote itself unless you type 2 after each other, so you can escape a single quote by typing 2 like in vbscript: msgbox "a ""test"" here" i hope you know what i mean '([^']|'')*' Edited July 26, 2017 by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Malkey Posted July 26, 2017 Posted July 26, 2017 Try this. #include <array.au3> $regexp = StringRegExp("test 'a b c' string 'd e f'", "'([^']+)'|[^']+", 3) _ArrayDisplay($regexp) $string = "a ""test"" here" ; Is correct for single double quotes arround "Test" ConsoleWrite($string & @CRLF) $string1 = 'a ""test"" here' ; Will give two double quotes arround ""Test"" ConsoleWrite($string1 & @CRLF)
TheAutomator Posted July 26, 2017 Author Posted July 26, 2017 Uhm okay how do I explain it better.. lets replace the quotes by # #([^#]|##)*#|\S+ this works perfectly with the vbscript.regexp object as the pattern so why not in autoit? the string # test ## 123 ## done# abc123 #some other test# should split into: # test ## 123 ## done# abc123 # some other test # Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
Malkey Posted July 26, 2017 Posted July 26, 2017 I suppose vbscript.regexp is a different flavour. AutoIt uses Perl-compatible Regular Expressions (PCRE). #include <array.au3> $regexp = StringRegExp("# test ## 123 ## done# abc123 #some other test#", "(#(?:[^#]+|##)*#)|[^#]+", 3) _ArrayDisplay($regexp)
iamtheky Posted July 27, 2017 Posted July 27, 2017 (edited) $str = "# test ## 123 ## done# abc123 #some other test#" msgbox(0, '' , stringmid($str , 1 , stringinstr($str , "#" , 0 , 6)) & @CR & stringmid($str , stringinstr($str , "#" , 0 , 6) + 1 , stringinstr($str , "#" , 0 , 7) - stringinstr($str , "#" , 0 , 6) - 1) & @CR & stringmid($str , stringinstr($str , "#" , 0 , 7))) also this regex way #include <array.au3> $str = "# test ## 123 ## done# abc123 #some other test#" $split = stringreverse(_ArrayToString(StringRegExp(stringreverse($str) , "(#.*?#)(.*?)(#.*#)" , 3) , @CR)) msgbox(0, '' , $split) Edited July 27, 2017 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Malkey Posted July 27, 2017 Posted July 27, 2017 (edited) @iamtheky Using this:- "#some other test# abc123 # test ## 123 ## done#" as the test string, both your examples do not return an array like this:- #some other test# abc123 # test ## 123 ## done# as I expected But, we could differ in what to expect. Malkey Edited July 27, 2017 by Malkey Added "I" in "as I expected." and etc..
iamtheky Posted July 27, 2017 Posted July 27, 2017 (edited) Neither of my examples return an array at all, but are the splits not in the expected locations? Are you not entertained!? ah, nvm, i now see the edge case you manufactured. As well, there are plenty of arrangements that blow up all of the proposed solutions, thats on the OP tho. Edited July 27, 2017 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
TheAutomator Posted July 27, 2017 Author Posted July 27, 2017 18 hours ago, Malkey said: I suppose vbscript.regexp is a different flavour. AutoIt uses Perl-compatible Regular Expressions (PCRE). #include <array.au3> $regexp = StringRegExp("# test ## 123 ## done# abc123 #some other test#", "(#(?:[^#]+|##)*#)|[^#]+", 3) _ArrayDisplay($regexp) Ah i see, so that's why it doesn't work, just a different type of regex language.. I wanted to split a string into tokens like most parsers do with quoted strings. Thanks for the explanation and help Regards Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone MiniMark Editor
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