I’m trying to split the following string: "'aaa bbb' 0.05 ccc 3* 20*0.1"
so that the elements are:
0: aaa bbb
1: 0.05
2: ccc
3: 3*
4: 20*0.1
I then want to loop over each of the results. The following snippet handles the first 3 elements, but not the last two:
Regex
.Matches(input, @"(?<match>[-+]?[0-9]*\.?[0-9]+)|(?<match>\w+)|'(?<match>[\w\s]*)'")
.Cast<Match>()
.Select(m => m.Groups["match"].Value)
.ToList()
.ForEach(z => etc...
What should I add to the regex so that 3* and 20*0.01 are returned as single matches?
This regular expression matches the expressions the way you wanted:
produces this output:
All you need to do is detecting if a value has single quotes around it, and unquote if necessary.