Exemplo n.º 1
0
def test6():
    obj = VarPointer()
    sar = RegexpSar()
    myStr = "0123456 789"
    sar.add_regexp("\\d+",
                   lambda from_pos, to_pos: obj.set(myStr[from_pos:to_pos]))
    sar.match_at(myStr, 3)
    validate("3456", obj.val)
Exemplo n.º 2
0
def test20():
    # get match only at certain position
    myStr = "aa11 bb22 cc33 dd44"
    matchedStr4 = VarPointer()
    sar = RegexpSar()

    def call(from_pos, to_pos):
        matchedStr4.val = myStr[from_pos:to_pos]

    sar.add_regexp("\\w+", call)
    sar.match_at(myStr, 5)

    validate("bb22", matchedStr4.val)