Re: Regexps (was Re: Invalid Operating System)

[prev] [thread] [next] [lurker] [Date index for 2006/12/18]

From: Abigail
Subject: Re: Regexps (was Re: Invalid Operating System)
Date: 12:12 on 18 Dec 2006
--kXdP64Ggrk/fb43R
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Dec 18, 2006 at 12:47:58PM +0100, demerphq wrote:
> On 12/18/06, Abigail <abigail@xxxxxxx.xx> wrote:
> >On Sun, Dec 17, 2006 at 11:07:50PM -0800, Yoz Grahame wrote:
> >> On 12/17/06, Robert Rothenberg <robrwo@xxxxx.xxx> wrote:
> >> >
> >> >Bad comparison: traditional regexps are much easier to read than the=
=20
> >ones
> >> >used in contemporary programming languages.
> >>
> >> PCRE-style regexp in Javascript:
> >> regexp =3D /(\d{1,3}\.){3}\d{1,3}/;
> >>
> >> Traditional POSIX regexp in C:
> >> char regexp[] =3D "\\([:digit:]\{1,3\}\\.\\)\\{3\\}[:digit:]\\{1,3\\}";
> >>
> >> The second one is clearly the more horrific of the two hateful messes,
> >> but I'll give you that it's *way* more fun to type if you just can't
> >> get enough joyful bouncing on the backslash key.
> >> (And traditional POSIX holds an even deeper hate - backslashes EITHER
> >> switch a character from being a literal to a metacharacter, OR from a
> >> metacharacter to a literal, depending on the character in question.
> >> Consistency's for suckers, clearly.)
> >
> >
> >Well, so does Perl, and so your PCRE example. The latter backslashes
> >the d, turning the literal d into a metacharacter, and it backslashes
> >the ., turning the metacharacter . into the literal .
>=20
> In Perl the rule is: If its an alpha-numeric char then escaping it
> turns it into a meta pattern. If its non-alpha then escaping it turns
> it into a literal. The latter rule is hard, and afaik applies to every
> Perl. Hatefully tho perl will treat an unknown escape-alphanum
> sequence as an unescaped char, not even warning.


    $ perl -wle '"q" =3D~ /\q/ or print "Ping"'
    Unrecognized escape \q passed through at -e line 1.


Which to me seems that Perl treats an unknown escape-alphanum as an
unescape char and it warns it did so.


Abigail

--kXdP64Ggrk/fb43R
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)

iD8DBQFFhoWuBOh7Ggo6rasRApKYAJ4u2VasFMRRAUo3e3nt6NPF/0GdYQCfYa0I
yw/OQOdlmpBGnIgpRbW/EFM=
=QJZl
-----END PGP SIGNATURE-----

--kXdP64Ggrk/fb43R--
There's stuff above here

Generated at 22:02 on 27 Dec 2006 by mariachi 0.52