Short example of regular expression converted to a state machine?

后端 未结 6 1850
死守一世寂寞
死守一世寂寞 2020-11-29 04:30

In the Stack Overflow podcast #36 (http://blog.stackoverflow.com/2009/01/podcast-36/), this opinion was expressed: Once you understand how easy it is to set up a state machi

6条回答
  •  无人及你
    2020-11-29 05:27

    A rather convenient way to help look at this to use python's little-known re.DEBUG flag on any pattern:

    >>> re.compile(r'<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)', re.DEBUG)
    literal 60
    subpattern 1
      in
        range (65, 90)
      max_repeat 0 65535
        in
          range (65, 90)
          range (48, 57)
    at at_boundary
    max_repeat 0 65535
      not_literal 62
    literal 62
    subpattern 2
      min_repeat 0 65535
        any None
    literal 60
    literal 47
    groupref 1
    literal 62
    

    The numbers after 'literal' and 'range' refer to the integer values of the ascii characters they're supposed to match.

提交回复
热议问题