Nice puzzle. Thanks.
This pattern (aPatt below) gets the tokens separated, but I can't figure how to remove the outer quotes.
tallpaul() produces:
token1
token2
"token's 1a',1b'"
'token4"5"'
12
23.2
?
.
'token'
tok'en
to"ken
If you can figure out how to lose the outer quotes, please let us know.
This needs a reference to "Microsoft VBScript Regular Expressions" to work.
Option Explicit
''returns a list of matches
Function RegExpTest(patrn, strng)
Dim regEx ' Create variable.
Set regEx = New RegExp ' Create a regular expression.
regEx.Pattern = patrn ' Set pattern.
regEx.IgnoreCase = True ' Set case insensitivity.
regEx.Global = True ' Set global applicability.
Set RegExpTest = regEx.Execute(strng) ' Execute search.
End Function
Function tallpaul() As Boolean
Dim aString As String
Dim aPatt As String
Dim aMatch, aMatches
'' need to pad the string with leading and trailing spaces.
aString = " token1 token2 ""token's 1a',1b'"" 'token4""5""' 12 23.2 ? . 'token' tok'en to""ken "
aPatt = "(\s'[^']+'(?=\s))|(\s""[^""]+""(?=\s))|(\s[\w\?\.]+(?=\s))|(\s\S+(?=\s))"
Set aMatches = RegExpTest(aPatt, aString)
For Each aMatch In aMatches
Debug.Print aMatch.Value
Next
tallpaul = True
End Function