NYCPHP Meetup

NYPHP.org

[nycphp-talk] [OT] grep assistance

Peter Sawczynec ps at pswebcode.com
Tue Sep 26 08:11:27 EDT 2006


Sorry, this should match 628 - 781 only:

62[8-9]|6[3-9][0-9]|7[0-7][0-9]|78[0-1]

Peter

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of Peter Sawczynec
Sent: Tuesday, September 26, 2006 8:07 AM
To: 'NYPHP Talk'
Subject: Re: [nycphp-talk] [OT] grep assistance


62[8-9]|6[3-9][0-9]|7[0-8][0-1]

Using your clues, above will match 628 through 781 only, correct?

Peter

-----Original Message-----
From: talk-bounces at lists.nyphp.org [mailto:talk-bounces at lists.nyphp.org] On
Behalf Of Paul Houle
Sent: Tuesday, September 26, 2006 7:57 AM
To: NYPHP Talk
Subject: Re: [nycphp-talk] [OT] grep assistance


Peter Sawczynec wrote:
> Four grep regular expressions I could use help with...
    This is fun.  But it's certainly not a "best practice" way of doing 
things.  (Ask somebody to explain what the #4 regex does...)  I'll take 
a crack at it with PCRE's,  but it's very likely that some of them have 
mistakes on boundary cases.

    If you're working on the UNIX command line,  the easy way to do this 
is with awk.  If you're handling space separated data,  say

775 some data
776 other data

    you can write something like

awk '{if ($1<550} print}'

    awk defaults to space as a separator,  but you can change this with 
the -F option,  say -F: or -F,.  Somebody can look at that command and 
have a pretty clear idea of what it does and a decent chance of doing 
the right thing if 550 changes to 549.

    Note there is a bit of a cheat below in that I'm not considering 
proper fielding...  If you want to match any numbers embedded anywhere 
in the document,  I think you can change ^ -> (^|[^0-9]) and $ -> 
([^0-9]|$).  If you know numbers won't be at the beginning or end of a 
line and will be delimited by spaces,  you can replace ^ and $ with spaces.
>  
> 1) match all id numbers between 100 and 199

/^1[0-9]{2}$/
> 2) match all id numbers less than 550
/^4[0-9]{2}|5[0-4][0-9]$/
> 3) match all id numbers greater than 550
/^[0-9]{4,}|[6-9][0-9]{2}|55[1-9]$/
> 4) match all id numbers from 0-550, but not 400-480
>  
/^[0-3][0-9]{2}|48[1-9]|49[0-9]|5[0-4][0-9]$/
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php

_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com

Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php




More information about the talk mailing list