用python(V1.0)如何匹配HTML标签的实际操作

下的文章就是对python(V1.0)在实际相关应用方案的具体应用,如果你对python(V1.0)在匹配HTML标签的具体应用方案的具体介绍,如果你对其感兴趣的话,你就可以点击我们的文章。

  匹配HTML标签

 

 
 
 
  1. #coding:utf-8  
  2. import re  
  3. nStr = "<div>" 
  4. p = re.compile('</?\w+[^>]*>',re.I)  
  5. if p.match(nStr):  
  6. print "exists"   

输出

 

 
 
 
  1. else:  
  2. print "not"  
  3.  

 

URL相关匹配EMAIL地址

 

 
 
 
  1. import re  
  2. nStr = "[email protected]" 
  3. p = re.compile('^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$',re.S)  
  4. if p.match(nStr):  
  5. print "exists"  
  6. else:  
  7. print "not"  
  8.  

 

 

python(V1.0) 匹配URL

 

 
 
 
  1. import re  
  2. nStr = "http://localhost" 
  3. p = re.compile('^[a-zA-z]+://(\w+(-\w+)*)
    (\.(\w+(-\w+)*))*(\?\S*)?$',re.S)  
  4. if p.match(nStr):  
  5. print "exists"  
  6. else:  
  7. print "not"  

 

 

以上的文章就是对python(V1.0 匹配HTML标签与匹配URL的实际相关应用方案的介绍。

【编辑推荐】

  1. Python复制文件的实际操作方案与代码详解
  2. Python矩阵转置中的二维数组的实际操作方案介绍
  3. Python socket编程在具体应用中前两个步骤的介绍
  4. Python Library中Condition的具体操作方案
  5. 在Python Library中Event具体实际操作方案

 

 

THE END