[Linux OT] Regular expresion question

Kevin O'Gorman kogorman
Tue Oct 5 08:14:33 PDT 2004


The ".9" specifies September.  The '.' matches any single character, while the
9 matches literally.  Since the only candidates are going to be 09,
this does the
trick.  To match just November, you'd have to use "11", because ".1" would match
both January (01) and November(11), while "1." would match 10, 11 and 12.

Number ranges are a bit hard in regular expressions because REs are not
designed for any numeric interpretation at all.  They are purely text matches.
Character ranges like [0-5] can help, but they are not the same thing.

++ kevin

On Tue, 05 Oct 2004 05:37:16 -0500, Jean Sagi <jeansagi at uniweb.net.co> wrote:
> 
> You example works for the case I give. Thanks.
> 
> I didn't understand ".9" in the patterns you gave; what they are used for?
> 
> The pattern works with them and without them, I mean the next statement
> works the way I want:
> 
>    [chucho at oolnta hist]$ ls | grep -e "^h1[0-9].9" -e "^h2[0-5].9"
>    h100904
>    h120904
>    h130904
>    h180904
>    h200904
>    h240904
>    h250904
> 
>    [chucho at oolnta hist]$ ls | grep -e "^h1[0-9]" -e "^h2[0-5]"
>    h100904
>    h120904
>    h130904
>    h180904
>    h200904
>    h240904
>    h250904
> 
> Finally I wonder if there is a more generic way of handling ranges with
> regular expresions, or maybe I'm trying to use the way they are not
> meant to.
> 
> Chucho!
> 
> 
> 
> Brad De Vries wrote:
> > Jean, you could try sed using the following syntax:
> > $ sed -n -e "/^h1[0-9].9/p" -e "/^h2[0-5].9/p"
> >
> >
> 
> _______________________________________________
> Linux-users mailing list
> Linux-users at linux-sxs.org
> http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
> 


-- 
Go back to the top: I almost always top-post
Kevin O'Gorman, PhD


More information about the Linux-users mailing list