Forum: Cfengine Help
Subject: Re: Cfengine Help: Function readstringarrayidx () - Need Regex help
Author: joe77
Link to topic: https://cfengine.com/forum/read.php?3,22626,22675#msg-22675

i Daniel,
thanks for your great answer. I like your regex but strangely in Cfengine 
(unlike in a testing application ("the regex coach") it will not work. 
(Cfengine just puts the first linie into the array and if the first linie of 
the data file ist NOT fitting to the regex it will not put any line into the 
array) 

I have some questions: 
Will cfengine view the file as ONE long line or will it use the file 
"line-by-line".
For me it seems like in Cfengine ^ and $ representing "start of text" and "end 
of text" and NOT "start of line" and "end of line".


That might be the reason why your the answer of Daniel is not working.

Is there a possibility to "tell" cfengine to use ^ and $ as start of line and 
end of line ancor?

Or is this not a Cfengine issue? Is it due to my little knowledge about regexes?

After a lot of trying i am really lost in there :(

-Joe



Daniel V. Klein Wrote:
-------------------------------------------------------
> You're using the "comment" regex to match lines
> that DON'T look like something... Try this:
> 
> "dim_array" int =>
> readstringarrayidx("array","datafile","^(?!VM;[^;]
> *;name1;).+",";",10,10000);
> 
> The regex says "anything, as long as you don't
> seeVM;stuff;name1;, is a comment".  I think it'll
> work...
> 
> -Dan

> > 
> > Hi,
> > I have a problem with readstringarrayidx ()
> > 
> > 1. I want to read from this example datafile
> > #######################
> > VM;bv10;name1;vlan142;192
> > VM;bv11;name2;vlan122;102
> > VM;bv12;name1;vlan102;103
> > ########################
> > 
> > I want to select the lines where "VM" and
> "name1" are present (line 2 should be "removed") 
> but i am not getting the regexp correct. Tried
> maaaany different ones ;) 
> > I just started to learn about regular
> expressions. I know that this function is
> unanchored. But using anchors like "^" or "$"
> didnt work either.
> > 
> > ####################
> > REGEX= VM.*name1.* 
> > "dim_array" int =>
> readstringarrayidx("array","datafile","REGEX",";",
> 10,10000);
> > #######
> > Can someone give me a hint about finding the
> correct REGEX?
> > Thanks in advance
> > Joe

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to