Closed supperthomas closed 2 years ago
^ 为匹配输入字符串的开始位置。
[0-9]+匹配多个数字, [0-9] 匹配单个数字,+ 匹配一个或者多个。
abc$匹配字母 abc 并以 abc 结尾,$ 为匹配输入字符串的结束位置
这个很好用,在线能用。 https://regex101.com/
【10分钟快速掌握正则表达式-哔哩哔哩】 https://b23.tv/UVEzWx3
re.M 多行模式
\g<0> 匹配前面所有
compile(pattern, flags=0) Compile a regular expression pattern, returning a Pattern object.
escape(pattern)
Escape special characters in a string.
findall(pattern, string, flags=0)
Return a list of all non-overlapping matches in the string.
If one or more capturing groups are present in the pattern, return
a list of groups; this will be a list of tuples if the pattern
has more than one group.
Empty matches are included in the result.
finditer(pattern, string, flags=0)
Return an iterator over all non-overlapping matches in the
string. For each match, the iterator returns a Match object.
Empty matches are included in the result.
fullmatch(pattern, string, flags=0)
Try to apply the pattern to all of the string, returning
a Match object, or None if no match was found.
match(pattern, string, flags=0)
Try to apply the pattern at the start of the string, returning
a Match object, or None if no match was found.
purge()
Clear the regular expression caches
search(pattern, string, flags=0)
Scan through string looking for a match to the pattern, returning
a Match object, or None if no match was found.
split(pattern, string, maxsplit=0, flags=0)
Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings. If
capturing parentheses are used in pattern, then the text of all
groups in the pattern are also returned as part of the resulting
list. If maxsplit is nonzero, at most maxsplit splits occur,
and the remainder of the string is returned as the final element
of the list.
sub(pattern, repl, string, count=0, flags=0)
Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the Match object and must return
a replacement string to be used.
subn(pattern, repl, string, count=0, flags=0)
Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
string by the replacement repl. number is the number of
substitutions that were made. repl can be either a string or a
callable; if a string, backslash escapes in it are processed.
If it is a callable, it's passed the Match object and must
return a replacement string to be used.
template(pattern, flags=0)
Compile a template pattern, returning a Pattern object
匹配注释
\/\*.+\*\/
查找某个宏定义
^\s*#\s*define\s+RTTHREAD.*\n
有了这个库,以后再也不用写正则表达式了!
?
通配符匹配文件名中的 0 个或 1 个字符,*
通配符匹配零个或多个字符 '\s' 匹配任意空格 ^ 断言位于一行 的起始位置 ‘\d’ 匹配任意[0-9] '+' 匹配前面任意 '\n' 匹配换行.
匹配除换行符(\n、\r)之外的任何单个字符,相等于 [^\n\r]。