Question

I learned online that we can grep with AND statement by .*, i.e.:

aptitude search jdk | grep '7.*doc\|doc.*7'

_ _ _ _ p openjdk-7-doc - OpenJDK Development Kit (JDK) documentation
, this works well.

but if we just use *, i.e.:

aptitude search jdk | grep '7*doc\|doc*7'

_ _ _ _ p default-jdk-doc - Standard Java or Java compatible Developme
_ _ _ _ p openjdk-6-doc - OpenJDK Development Kit (JDK) documentatio
_ _ _ _ p openjdk-7-doc - OpenJDK Development Kit (JDK) documentatio
, this does not work well.

What is the meaning of the dot before the star(/Asterisk) ?

Était-ce utile?

La solution

note: regular expression syntax may vary among different programs...

in grep the . means "any character". * means; the previous character repeated 0, 1 or more times. So your expression

7.*

means: a 7 followed by "any character", repeated any number of times (0, 1 or more), ie: a 7 followed by any succession of characters. The other expression

7*

means: the character 7, repeated 0, 1 or more times; thus matching any document; only the rest of your regular expression is still working...

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top