Skip to main content
IBM 
ShopSupportDownloads
IBM HomeProductsConsultingIndustriesNewsAbout IBM
IBM : developerWorks : Linux : Education - Tutorials
LPI certification 101 exam prep, Part 2
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
2. Regular expressions
  


The "*" metacharacter page 9 of 11


Some metacharacters don't match anything in themselves, but instead modify the meaning of a previous character. One such metacharacter is * (asterisk), which is used to match zero or more repeated occurrences of the previous character. Here are some examples:

  • ab*c (matches abbbbc but not abqc)
  • ab*c (matches abc but not abbqbbc)
  • ab*c (matches ac but not cba)
  • b[cq]*e (matches bqe but not eb)
  • b[cq]*e (matches bccqqe but not bccc)
  • b[cq]*e (matches bqqcce but not cqe)
  • b[cq]*e (matches bbbeee)
  • .* (matches any string)
  • foo.* (matches any string that begins with foo)

The line ac matches the regex ab*c because the asterisk also allows the preceding expression (c) to appear zero times. Note that the * regex metacharacter is interpreted in a fundamentally different way than the * glob character.


Main menuSection menuFeedbackPreviousNext
PrivacyLegalContact