[Chicago-talk] regural expression question?

Richard Reina richard at rushlogistics.com
Thu Mar 30 07:07:53 PST 2006


Ahh, the magic parenthesis...
 Thanks Joshua.
Joshua McAdams <joshua.mcadams at gmail.com> wrote: > > I have a little script that finds the line which
> > contains a six digit number begining with 1 or
> > greater.  I know that $_ represents the line,
> > however, I am having trouble figuring out how to
> > save that number once it's found (without everything
> > else in the line).
> >
> >  #!/usr/bin/perl -w
> >
> >  @ARGV = "/home/richard/test/out.txt";
> >  while (<>) {
> >      if ( /\b[123456789][0-9][0-9][0-9][0-9][0-9]\b/
> > ) {
> >          print "Found\n" . $_ . "\n";
> >      }
> >  }
> >

Put some parenthesis around the expression...

if ( /\b([123456789][0-9][0-9][0-9][0-9][0-9])\b/ ) {
    print "Found\n" . $1 . "\n";
}

I think that you could tighten up the expression a little too...

if ( /\b([1-9]\d{5})\b/ ) {
    print "Found\n" . $1 . "\n";
}
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk



A people that values its privileges above its principles soon loses both.
 -Dwight D. Eisenhower.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20060330/fe3912d1/attachment.html


More information about the Chicago-talk mailing list