[svlug] Lex question about variable length fields

Robert Hajime Lanning lanning at lanning.cc
Thu May 22 17:06:13 PDT 2014


On 05/22/14 16:54, Jesse Monroy wrote:
> Robert,
> your answer is not helpful.
>
> Bob,
> here are some notes on Regular Expression
>
> http://bsdmasterindex.com/talks/

I know regex.  I have never dealt with lex, specifically.

I am just saying, that while it might be possible for lex to do what he 
wants, most CLI that I have dealt with handle it differently.

$ read VAR1 VAR2 VAR3 RESTOFLINE

there, in shell it works just fine...

So he should move into perl and do:
/^ *(\w+) +(\w+) +(\w+) +(.*)$/;
$var1 = $1;
$var2 = $2;
$var3 = $3;
$restofline = $4;

Of course, he can use character classes if he wants to be more specific 
in what he accepts, or have more than just space for a delimiter.  It 
also does not handle quoting and escaping.

what do you do with a commandline that is:
"hello there" "my name" "is of" no importance

I was just saying it might be simpler if you just let lex to the 
tokenization.  Let it return an array of X elements, then pop off the 
first three and join the rest.

-- 
Mr. Flibble
King of the Potato People
http://www.linkedin.com/in/RobertLanning




More information about the svlug mailing list