grouping and greedy operations. : group « Regular Expressions « Python Tutorial

Python Tutorial
1. Introduction
2. Data Type
3. Statement
4. Operator
5. String
6. Tuple
7. List
8. Dictionary
9. Collections
10. Function
11. Class
12. File
13. Buildin Function
14. Buildin Module
15. Database
16. Regular Expressions
17. Thread
18. Tkinker
19. wxPython
20. XML
21. Network
22. CGI Web
23. Windows
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorial
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python Tutorial » Regular Expressions » group 
16. 3. 2. grouping and greedy operations.
import re

formatString1 = "%-22s: %s"   # string to format output 

testString1 = "phone: 123-4567, e-mail: a@server.com"
expression1 = r"(\w+ \w+), phone: (\d{3}-\d{4}), e-mail: (\w+@\w+\.\w{3})"

formatString2 = "%-38s: %s"   # string to format output

pathString = "/books/2001/python"  # file path string

expression2 = "(/.+)/"  # greedy operator expression
print formatString1 % "Greedy error",re.matchexpression2, pathString ).group) )

expression3 = "(/.+?)/"  # non-greedy operator expression
print formatString1 % "No error, base only",re.matchexpression3, pathString ).group) )
16. 3. group
16. 3. 1. obtain a tuple of all the subgroups matched:
16. 3. 2. grouping and greedy operations.
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.