Jump to content

Recommended Posts

Posted (edited)
  On 7/26/2017 at 9:55 PM, Malkey said:

This matches one "not single quote" character.

[^']

 

Expand  

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 by TheAutomator
Posted (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 by iamtheky

  Reveal hidden contents

Posted (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 by Malkey
Added "I" in "as I expected." and etc..
Posted (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 by iamtheky

  Reveal hidden contents

Posted
  On 7/26/2017 at 11:35 PM, 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)

 

Expand  

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...