1. Computing

Python Regular Expression Examples: Square Braces or Brackets

From , former About.com Guide

Definition:
 >>> import re 
 >>> list = ['cat', 'car', 'cap', 'cab', 'cad', 'can', 'Cancun', 'Katze', 'Auto', 'Deckel', 'Droschke', 'Flegel', 'Dose', 'Vogel', 'CHAT', 'VOITURE', 'CHAPEAU', 'CABINE', 'DAO', 'BIDON', 'BONBON'] 
 >>> y = re.compile('a[dtn]') 
 >>> for x in list: 
 ... if re.search(y,x): 
 ... print x 
 ... 
 cat 
 cad 
 can 
 Cancun 
 Katze 
 >>> y = re.compile('[aeiou][dtn]') 
 >>> for x in list: 
 ... if re.search(y,x): 
 ... print x 
 ... 
 cat 
 cad 
 can 
 Cancun 
 Katze 
 Auto 

Back to the main index of this glossary
Top Related Searches car cap cat car x cat dtn bidon chapeau
  1. About.com
  2. Computing
  3. Python
  4. Regular Expressions
  5. Python RegEx Examples
  6. Grouping and Alternating
  7. Python RegEx - Python Regular Expressions - Examples - Square Braces or Brackets

©2013 About.com. All rights reserved.