how to find spaces with a regex?
Nix, Robert P.
Nix.Robert at mayo.edu
Thu Feb 19 18:20:50 UTC 2004
grep " *" filename will also work, as does "\s*". "\s\{2,3\}" did not work for me, but " \{2,3\}" does. Actually, to get the desired results, I ended up using a regex of "\b \{2,3\}\b", because {2,3} matched three spaces, but really didn't care if the character following it was also a space.
grep "\b[:space:]*\b" filename works, but not "\b[:space:]\{2,3\}\b".
The command "perl -n -e "print if m/\b\s{2,3}\b/" filename works as does "perl -n -e "print if m/\b {2,3}\b/" filename .
So my question becomes: In grep, why won't the braced notation work with the symbolics for spaces when * and + do?
----
Robert P. Nix internet: nix.robert at mayo.edu
Mayo Clinic phone: 507-284-0844
RO-CE-8-857 page: 507-270-1182
200 First St. SW
Rochester, MN 55905
---- "Codito, Ergo Sum"
"In theory, theory and practice are the same,
but in practice, theory and practice are different."
> -----Original Message-----
> From: fedora-list-admin at redhat.com [SMTP:fedora-list-admin at redhat.com] On Behalf Of Vincent
> Sent: Thursday, February 19, 2004 10:23 AM
> To: fedora-list at redhat.com
> Subject: Re: how to find spaces with a regex?
>
> On Thu, 19 Feb 2004 11:11:29 -0400
> Trevor Smith <trevor at haligonian.com> wrote:
>
> > On February 18, 2004 11:28 pm, Trevor Smith wrote:
> >
> > > can NOT figure out how to use a regex to search for multiple spaces -- for
> >
> > Sorry, I figured it out.
> >
> > grep ' {1,}' filename
> >
> > does not work
> >
> > grep ' \{1,\}' filename
> >
> > does work. I was forgetting to escape the { and } characters.
> >
> > --
> > Trevor Smith | trevor at haligonian.com
> >
> >
> > --
> > fedora-list mailing list
> > fedora-list at redhat.com
> > To unsubscribe: http://www.redhat.com/mailman/listinfo/fedora-list
>
> for future reference \s means space \t means tab \S means NON-whitespace
More information about the fedora-list
mailing list