Re: Simple regex question



On Sun, 24 Jan 2010 14:23:59 +0100, Janis Papanagnou wrote:

Stephane CHAZELAS wrote:
2010-01-24, 06:11(+01), Janis Papanagnou:
Seebs wrote:
I'm not sure that even ksh can do everything posix REs can.
I am confident and quite sure it does. Vice versa; I think the regexp
library will at least have problems emulating ksh's !(...)
construct. Ever tried? In general you'll get extremely bulky results
here! But the class of languages (regular expressions) is the same,
anyway.[*]

[*] N.B. Newer ksh's also support back-references in their
expressions, so strictly speeking, with that feature, they exceed the
Chomsky-3 grammar class as well (analogous to other libraries with
backreference extensions).
[...]

Recent versions of AT&T ksh can also convert globbing patterns to
regular expressions (a AT&T variant thereof):

$ ksh -c 'printf "%R\n" "!(...)"'
^(\.\.\.)!$

I didn't knew that ! were a regular expression meta operator in regexp.

The ! _regexp_ meta operator does not seem to produce results on my box.

$ ls
hello hello world helloworld regexp world $ ls !(hello)
hello world helloworld regexp world $ ksh -c 'printf "%R\n"
"!(hello)"'
^(hello)!$
$ ls | egrep '^(hello)!$'
### nothing matched ###

It works well with the known operators + and * etc. resp. +(...) *(...)
etc.

Still interested in an regexp expression conforming to !(...) ext. glob.

The grep from AST will handle this '^(hello)!$' if you give it a -X flag
to enable the augmented expressions.

An instant thought on matching !(hello) with a RE, this is

^([^h].*|h[^e].*|he[^l].*|hel[^l].*|hell[^o].*|hello..*)$

There has been discussion on comp.compilers recently on calculating the
difference between two regular expressions.
.



Relevant Pages

  • Re: regexp advice
    ... > I am working on a "file parsing" app using regular expressions. ... based on the User-defined tokens. ... > set string "N0010G01X10Y12M10" ... > foreach regexp $regList { ...
    (comp.lang.tcl)
  • Re: Simple regex question
    ... In general you'll get extremely bulky results ... But the class of languages (regular expressions) is the same, ... Chomsky-3 grammar class as well (analogous to other libraries with ... _regexp_ meta operator does not seem to produce results on my box. ...
    (comp.unix.shell)
  • Re: RegExp as Finite State Machine
    ... RegExp is a FSM, both describe a regular language. ... language it accepts is regular -- Regular Expressions. ...
    (comp.lang.javascript)
  • Re: casts
    ... regular expressions as a mathematical formalism because there has been ... This has nothing to do with C; regexp libraries behave the same way ... So far as destroying regexps as a "mathematical formalism" goes, ...
    (comp.lang.c)
  • Re: Is there any regexp and hashtable management in Excel VBA?
    ... Use Regular Expressions in Microsoft Visual Basic 6.0 ... Should work for VBA as well. ... But the keyword "Regexp" is not available. ... resulting text from the hard disk. ...
    (microsoft.public.excel.programming)