lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Russell Haley once stated:
> Since my match and capture understanding in Lua is somewhat weak I am
> looking for opportunities to improve my understanding. There is a SO
> question about parsing a file here:
> 
> https://unix.stackexchange.com/questions/422526/remove-comma-outside-quotes
> 
> The crux of the question is to leave the commas within a quoted items
> and replace all the outer "separator" commas with tilde (~). 

  [ snip ]

> - Is it possible to do this in a single call to gsub (I'm hoping yes)?
> If not, I will look first at one or two calls (i.e. match and then
> gsub) and using a loop.
> - Is this something that would be better done with LPEG?

  Yes.  Also, a few more examples that probably need to be addressed:

	123,"ABC, DEV 23",345,,202,NAME
	,"ABC, DEV 23",345,534,202,NAME
	123,"ABC, DEV 23",345,534.202,
	123 , "ABC, DEV 23" , 345 , 534 , 202 , NAME
	123,"ABC, \"hello\", DEV 23",,,,NAME
	123,'ABC, "hello", DEV 23',342,534,202,NAME
	,,,,,,

  Which are allowed?  Which are disallowed?  Are these errors?  What?

  -spc