Re: how to find spaces with a regex?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Nix, Robert P. wrote:
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?

grep "\b[[:space:]]\{2,3\}\b" filename works.
According to the manpage, [:space:] is only valid inside a bracket, so I don't know why "\b[:space:]*\b" works...


I don't think grep actually uses \s to mean a space... at least 'man grep' doesn't appear to mention it... although many other regexps do.




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux