加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 活动 > 正文

python 正则表达式语法学习笔记

发布时间:2020-12-02 06:55:50 所属栏目:活动 来源:网络整理
导读:正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配。这篇文章主要介绍了python 正则表达式语法记录,需要的朋友可以参考下

  短视频,自媒体,达人种草一站服务

正则表达式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配。这篇文章主要介绍了python 正则表达式语法记录,需要的朋友可以参考下

正则表达式(regular expression)描述了一种字符串匹配的模式(pattern),可以用来检查一个串是否含有某种子串、将匹配的子串替换或者从某个串中取出符合某个条件的子串等。

Python 自1.5版本起增加了re 模块,它提供 Perl 风格的正则表达式模式。

re 模块使 Python 语言拥有全部的正则表达式功能。

compile 函数根据一个模式字符串和可选的标志参数生成一个正则表达式对象。该对象拥有一系列方法用于正则表达式匹配和替换。

本文重点给大家介绍python 正则表达式语法。

The special characters are:

"." Matches any character except a newline.

"^" Matches the start of the string.

"$" Matches the end of the string or just before the newline at

the end of the string.

"*" Matches 0 or more (greedy) repetitions of the preceding RE.

Greedy means that it will match as many repetitions as possible.

"+" Matches 1 or more (greedy) repetitions of the preceding RE.

"?" Matches 0 or 1 (greedy) of the preceding RE.

*?,+?,?? Non-greedy versions of the previous three special characters.

{m,n} Matches from m to n repetitions of the preceding RE.

{m,n}? Non-greedy version of the above.

"" Either escapes special characters or signals a special sequence.

[] Indicates a set of characters.

A "^" as the first character indicates a complementing set.

"|" A|B, creates an RE that will match either A or B.

(...) Matches the RE inside the parentheses.

The contents can be retrieved or matched later in the string.

(?aiLmsux) Set the A, I, L, M, S, U, or X flag for the RE (see below).

(?:...) Non-grouping version of regular parentheses.

(?P...) The substring matched by the group is accessible by name.

(?P=name) Matches the text matched earlier by the group named name.

(?#...) A comment; ignored.

(?=...) Matches if ... matches next, but doesn't consume the string.

(?!...) Matches if ... doesn't match next.

(?<=...) Matches if preceded by ... (must be fixed length).

(?

申请创业报道,分享创业好点子。点击此处,共同探讨创业新机遇!

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读