Re: Split on whitespace except for between quotes

2019-09-10 Thread Neil_H
Regex (w*b)*?|(?<=").*(?=")$

Re: Split on whitespace except for between quotes

2019-09-07 Thread squattingmonk
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

Re: Split on whitespace except for between quotes

2019-09-07 Thread squattingmonk
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!

Re: Split on whitespace except for between quotes

2019-09-07 Thread kaushalmodi
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**

Re: Split on whitespace except for between quotes

2019-09-07 Thread r3c
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

Re: Split on whitespace except for between quotes

2019-09-07 Thread SolitudeSF
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)

Re: Split on whitespace except for between quotes

2019-09-07 Thread mratsim
iterate on the string, keep a counter on your quote nesting level, only split if that counter is zero.

Split on whitespace except for between quotes

2019-09-07 Thread squattingmonk
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