supperthomas / bluetoothlover_doc

this is about the learning station about friends.
https://supperthomas-wiki.readthedocs.io/
Apache License 2.0
46 stars 25 forks source link

正则表达式语法 #358

Closed supperthomas closed 2 years ago

supperthomas commented 2 years ago

? 通配符匹配文件名中的 0 个或 1 个字符, * 通配符匹配零个或多个字符 '\s' 匹配任意空格 ^ 断言位于一行 的起始位置 ‘\d’ 匹配任意[0-9] '+' 匹配前面任意 '\n' 匹配换行 . 匹配除换行符(\n、\r)之外的任何单个字符,相等于 [^\n\r]。

supperthomas commented 2 years ago

https://www.runoob.com/regexp/regexp-tutorial.html

supperthomas commented 2 years ago

^ 为匹配输入字符串的开始位置。

[0-9]+匹配多个数字, [0-9] 匹配单个数字,+ 匹配一个或者多个。

abc$匹配字母 abc 并以 abc 结尾,$ 为匹配输入字符串的结束位置

supperthomas commented 2 years ago

https://docs.python.org/zh-cn/3/library/re.html

supperthomas commented 2 years ago

这个很好用,在线能用。 https://regex101.com/

supperthomas commented 2 years ago

【10分钟快速掌握正则表达式-哔哩哔哩】 https://b23.tv/UVEzWx3

supperthomas commented 2 years ago

在线 https://regexr.com/ https://regexr-cn.com/

supperthomas commented 2 years ago

https://codejiaonang.com/#/course/regex_chapter1/0/1

supperthomas commented 2 years ago

re.M 多行模式

supperthomas commented 2 years ago

https://ihateregex.io/

supperthomas commented 2 years ago

\g<0> 匹配前面所有

supperthomas commented 2 years ago

https://www.cnblogs.com/zeke-python-road/p/9556117.html

supperthomas commented 2 years ago

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
supperthomas commented 2 years ago
修饰符 | 描述 -- | -- re.I | 使匹配对大小写不敏感 re.L | 做本地化识别(locale-aware)匹配 re.M | 多行匹配,影响 ^ 和 $ re.S | 使 . 匹配包括换行在内的所有字符 re.U | 根据Unicode字符集解析字符。这个标志影响 \w, \W, \b, \B. re.X | 该标志通过给予你更灵活的格式以便你将正则表达式写得更易于理解。
supperthomas commented 2 years ago

https://www.runoob.com/python/python-reg-expressions.html

supperthomas commented 2 years ago

匹配注释

\/\*.+\*\/
supperthomas commented 2 years ago

查找某个宏定义

^\s*#\s*define\s+RTTHREAD.*\n
supperthomas commented 2 years ago

有了这个库,以后再也不用写正则表达式了!

https://mp.weixin.qq.com/s/glVe3CNq6yBB6aezZ8t7FQ

supperthomas commented 1 year ago

https://www.cnblogs.com/klb561/p/14599946.html