Regex
(w*b)*?|(?<=").*(?=")$
Thanks! I came up with the following:
import parseutils, strutils
proc splitArgs(args: string): seq[string] =
var
parsed, tmp: string
i, quotes: int
while i < args.len:
i += args.parseUntil(parsed, Whitespace, i) + 1
This text wouldn't be passed into the command line (it's read from a file), but
it will be passed to it. Your suggestion turned me on to `parseCmdLine()` from
the os module. It does exactly what I need. Thank you!
Assuming that that input is from the command line, you can use the inbuilt
commandLineParams() instead of manually parsing it (example in my notes:
[https://scripter.co/notes/nim/#command-line-parameters)](https://scripter.co/notes/nim/#command-line-parameters\)).
Though, I use the **cligen**
Try this
import strutils
var str = "spam eggs \"spam and eggs\" asd zxc"
var spl = str.split("\"")
for s in 0..spl.high:
if spl[s].startsWith(" ") or spl[s].endsWith(" "):
spl[s] = spl[s].strip
echo spl
Run
i made library that does maybe a bit more than you need, but it can handle this
case [https://github.com/SolitudeSF/shlex](https://github.com/SolitudeSF/shlex)
iterate on the string, keep a counter on your quote nesting level, only split
if that counter is zero.
I want to split a string on whitespace, but keep strings that are between
quotes:
input: spam eggs "spam and eggs"
output: @["spam", "eggs", "spam and eggs"]
I want to support both single and double quotes, and I'm having trouble
wrapping my brain around how to do this. I've