Regex explanation..

Jerome Jean Verleyen <[email protected]> Thu, 21 Nov 2024 11:45:37 -0800 (PST)
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
------=_Part_13892_584141008.1732218337370
Content-Type: multipart/alternative; 
	boundary="----=_Part_13893_499244561.1732218337370"

------=_Part_13893_499244561.1732218337370
Content-Type: text/plain; charset="UTF-8"

Dear all.

I'm using the book Learning CFEngine 3, to trying to configure some 
computer here.
I wrote the code to detect the specific ethernet card that have some 
specific ipv4 format. In my case, "172.16.1.*".

What i notice is that i could not escape the point caracter ".". For 
example, this code don't detect anything:

 bundle agent my_test
{

  vars:
      "ipregex" string => "172\.16\.1\.*";

  classes:
      "found" expression => regcmp("$(ipregex)","172.16.1.10");
      
  reports:
    found::
      "Found the ip ";

    !found::
      " Don't found the ip";
     
}

bundle agent __main__
{
      methods: "my_test";
}

Running this promise get me back:

R:  Don't found the  ip

But if i change the regex to "172.16.1.*" :

R: Found the  ip

Even if i put a wrong ip like this: 

"found" expression => regcmp("$(ipregex)","172a16.1.10");

R: Found the  ip

I've read about PCRE Regex and "." is considered as any caracter.. So, why 
i could not "escape" the point "\." in my rule? 

Hope that's someone could explain this!
Regards

-- 
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/help-cfengine/fb14c68a-01e7-4877-a1b5-5f6a58f7bdf7n%40googlegroups.com.

------=_Part_13893_499244561.1732218337370
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div>Dear all.</div><div><br /></div><div>I'm using the book Learning CFEng=
ine 3, to trying to configure some computer here.</div><div>I wrote the cod=
e to detect the specific ethernet card that have some specific ipv4 format.=
 In my case, "172.16.1.*".</div><div><br /></div><div>What i notice is that=
 i could not escape the point caracter ".". For example, this code don't de=
tect anything:</div><div><br /></div><div>=C2=A0bundle agent my_test<br />{=
<br /><br />=C2=A0 vars:<br />=C2=A0 =C2=A0 =C2=A0 "ipregex" string =3D&gt;=
 "172\.16\.1\.*";<br /><br />=C2=A0 classes:<br />=C2=A0 =C2=A0 =C2=A0 "fou=
nd" expression =3D&gt; regcmp("$(ipregex)","172.16.1.10");</div><div>=C2=A0=
 =C2=A0 =C2=A0 <br />=C2=A0 reports:<br />=C2=A0 =C2=A0 found::<br />=C2=A0=
 =C2=A0 =C2=A0 "Found the ip ";<br /><br />=C2=A0 =C2=A0 !found::<br />=C2=
=A0 =C2=A0 =C2=A0 " Don't found the ip";<br />=C2=A0 =C2=A0 =C2=A0<br />}<b=
r /><br />bundle agent __main__<br />{<br />=C2=A0 =C2=A0 =C2=A0 methods: "=
my_test";<br />}</div><div><br /></div><div>Running this promise get me bac=
k:</div><div><br /></div><div>R: =C2=A0Don't found the =C2=A0ip</div><div><=
br /></div><div>But if i change the regex to "172.16.1.*" :</div><div><br /=
></div><div>R: Found the =C2=A0ip</div><div><br /></div><div>Even if i put =
a wrong ip like this: <br /></div><div><br /></div><div>"found" expression =
=3D&gt; regcmp("$(ipregex)","172a16.1.10");</div><div><br /></div><div>R: F=
ound the =C2=A0ip</div><div><br /></div><div>I've read about <span>PCRE Reg=
ex and "." is considered as any caracter.. So, why i could not "escape" the=
 point "\." in my rule? <br /></span></div><div><span><br /></span></div><d=
iv><span>Hope that's someone could explain this!</span></div><div><span>Reg=
ards<br /></span></div><div><span><br /></span></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;help-cfengine&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:[email protected]">help-=
[email protected]</a>.<br />
To view this discussion visit <a href=3D"https://groups.google.com/d/msgid/=
help-cfengine/fb14c68a-01e7-4877-a1b5-5f6a58f7bdf7n%40googlegroups.com?utm_=
medium=3Demail&utm_source=3Dfooter">https://groups.google.com/d/msgid/help-=
cfengine/fb14c68a-01e7-4877-a1b5-5f6a58f7bdf7n%40googlegroups.com</a>.<br /=
>

------=_Part_13893_499244561.1732218337370--

------=_Part_13892_584141008.1732218337370--