Lucifellow
Lucifellow

Reputation: 37

Zero Occurrence in regular Expressions (Unix)

Can someone explain what it means by zero occurrence when we use * as regular expression while using it with egrep or grep?

Suppose I have an expression like: "a*"

Does that means I have a pattern which starts with a or aaaaa..... or bob or does it have to start with a?

Upvotes: 2

Views: 1683

Answers (1)

J_H
J_H

Reputation: 20450

You are correct, a* will match bob, as will ^ba*o and ^boa*, since the Kleene star matches zero or more occurrences.

Consider the word bazaar. You might use za*, zaa*, or zaaa*r to match it. To insist on one or more occurrences, you might use za+r. For two or more use zaa+r. To insist on exactly two occurrences, use za{2}r.

Upvotes: 1

Related Questions