regex question....

Gary Kline kline at thought.org
Sun Dec 5 04:32:59 UTC 2010


On Sat, Dec 04, 2010 at 06:49:45PM -0800, xSAPPYx wrote:
> On Sat, Dec 4, 2010 at 17:56,  <perryh at pluto.rain.com> wrote:
> > Joshua Gimer <jgimer at gmail.com> wrote:
> >
> >> On Sat, Dec 4, 2010 at 5:26 PM, Gary Kline <kline at thought.org> wrote:
> >> > I have tried :1,$/s/[0-9]][0-9][0-9]/foo/g
> >> Why not just %s/[0-9]*/foo/g
> >
> > Too broad -- it will match the null string.  (* means "zero or more
> > instances of" whatever preceded it.)
> >
> > Best RE I know for integers is
> >
> >  [1-9][0-9]*
> >
> > (or replace the 1 with a 0 if the strings in question might have
> > leading zeros).
> > _______________________________________________
> > freebsd-questions at freebsd.org mailing list
> > http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> > To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
> >
> 
> Also, the + operator means '1 or more' but needs escaped:  %s/[0-9]\+/foo/g


	Okay.  I thought that the + must be perl-only regex... .  Then,
	nutshell, the most simple expression [fewest keystrokes] would
	be:

	%s/[1-0][0-9]*/foo/g


> 

-- 
 Gary Kline  kline at thought.org  http://www.thought.org  Public Service Unix
           Journey Toward the Dawn, E-Book: http://www.thought.org
          The 7.97a release of Jottings: http://jottings.thought.org



More information about the freebsd-questions mailing list