root/trunk/lib/regexp.py @ 12642
1 | 5348 | aaronmk | # Regular expression processing
|
---|---|---|---|
2 | |||
3 | import re |
||
4 | |||
5 | 5352 | aaronmk | def sub_recursive(sub_func, str_): |
6 | '''
|
||
7 | @param sub_func(str_):str_, n
|
||
8 | '''
|
||
9 | while True: |
||
10 | str_, n = sub_func(str_) |
||
11 | if n == 0: break |
||
12 | return str_ |
||
13 | |||
14 | 5348 | aaronmk | def sub_nested(re_, repl, str_): |
15 | 5353 | aaronmk | return sub_recursive(lambda s: re.subn(re_, repl, s), str_) |