zoukankan      html  css  js  c++  java
  • re.search 与 re.match的区别

    search ⇒ find something anywhere in the string and return a match object.
    match ⇒ find something at the beginning of the string and return a match object.
    
    # example code:
    string_with_newlines = """something
    someotherthing"""
    
    import re
    
    print re.match('some', string_with_newlines) # matches
    print re.match('someother', 
                   string_with_newlines) # won't match
    print re.match('^someother', string_with_newlines, 
                   re.MULTILINE) # also won't match
    print re.search('someother', 
                    string_with_newlines) # finds something
    print re.search('^someother', string_with_newlines, 
                    re.MULTILINE) # also finds something
    
    m = re.compile('thing$', re.MULTILINE)
    
    print m.match(string_with_newlines) # no match
    print m.match(string_with_newlines, pos=4) # matches
    print m.search(string_with_newlines, 
                   re.MULTILINE) # also matches
    
  • 相关阅读:
    boostrapvalidator
    bootstrap 整理
    emil 的使用
    sass笔记
    sql 语句的优化
    多线程笔记
    mysql笔记
    react
    优雅的创建map/list集合
    spring中路径的注入
  • 原文地址:https://www.cnblogs.com/everfight/p/difference_between_match_and_search.html
Copyright © 2011-2022 走看看