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


下的文章就是对pythonV1.0)在实际相关应用方案的具体应用,如果你对pythonV1.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 = "hkebao@126.com" 
  3. p = re.compile('^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$',re.S)  
  4. if p.match(nStr):  
  5. print "exists"  
  6. else:  
  7. print "not"  
  8.  

pythonV1.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"  

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

相关内容

    暂无相关文章

评论关闭