Thursday, August 16, 2012

Re: Pattern matching question

On 16.08.12 03:15, Tony Mechelynck wrote:
> Oh, regular expressions work quite nicely, but AFAICT each of the
> Unix programs which uses them has an almost, but not quite, identical
> grammar for them. So they look familiar, but at some unexpected times
> the same regexp does just very slightly different things in different
> programs: IOW you have to check each time how regexps works for the
> software you are using _now_.

Sadly yes, if we let that happen. One way to avoid that irritation is to
avoid using awk AND sed AND perl, etc. Sticking to one of the two major
classes, Extended REs (EREs), or the obsolete Basic REs (BREs), is a
ripper of a start, I find. (e.g. use only egrep or "grep -E", and only
awk. There are then no differences.)

Interestingly:

$ man 7 regex # seems to think we are moving forward:

»Regular expressions ("RE"s), as defined in POSIX.2, come in two forms: modern
REs (roughly those of egrep; POSIX.2 calls these "extended" REs) and obsolete
REs (roughly those of ed(1); POSIX.2 "basic" REs). Obsolete REs mostly
exist for backward compatibility in some old programs; they will be discussed
at the end. POSIX.2 leaves some aspects of RE syntax and semantics open;
"(!)" marks decisions on these aspects that may not be fully portable to
other POSIX.2 implementations.«

Vim's bewildering variety of regex flavours must have its varied uses.
The "\v" variation is the only one worth using, I submit, because it
is near as dammit POSIX ERE. (At least close enough that I don't
remember any big surprises.) Now our text searcher, text processor, and
editor all use EREs. :-))

But why are EREs better than BREs? Because they greatly reduce the
painful obfuscation of backslash snowstorms which occur in BREs,
allowing us to read them without counting on fingers and toes every time
we hit backslashes.

I tried building Vim with a POSIX regex library once. The resulting
behaviour was a dream, except for the :help. It broke. :-(

Erik

P.S. OK, I can't remember what regex flavour Expect uses, but it is
nearly a decade since I last used it.

--
The wonderful thing about standards is that there are so many of them.
- Andy Tanenbaum

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: