[RndTbl] Oh great RE master

Sean Walberg sean at ertw.com
Wed May 9 22:13:20 CDT 2007

I think Gilles had another good idea with the [^[[:digit:]]]* to strip out
all the leading non-digits instead of the first greedy .*

Most often I find that if I start a regexp with .* it can be rewritten much
more simply by rethinking, often ending up in a [^X]*([X]+) pattern like
Gilles or the s/[^X]//g pattern like I did.  .*? does work wonders too, but
regexps written that way suffer from the "what the heck does this do?"
syndrome 6 months down the road :)

That said, having two .* in the same pattern usually ends up causing
problems because of the very reasons we've gone through, and is a good sign
to rethink the way you're matching.


On 5/9/07, Trevor Cordes <trevor at tecnopolis.ca> wrote:
> On  9 May, Sean Walberg wrote:
> > The * operator is greedy, in perl .*? probably would have worked, I'm
> > not sure if that feature exists in sed.  Google around for
> > "backtracking",
> Sean beat me to it.  Perl's non-greedy *? is what you want.  Without it
> you're taking the most left-most first.  I use perl's non-greedy
> modifiers *all* the time.  Plus, perl let's you use \d instead of the
> horrific posix [[:digit:]] syntax.
> _______________________________________________
> Roundtable mailing list
> Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable

Sean Walberg <sean at ertw.com>    http://ertw.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.muug.mb.ca/pipermail/roundtable/attachments/20070509/f7775e0f/attachment.html

More information about the Roundtable mailing list