Python Regular Expression
来源:互联网 发布:阿里云 储值卡 余额 编辑:程序博客网 时间:2024/05/26 12:56
Regular expression in Python
^
Matches the beginning of a line
$
Matches the end of the line
.
Matches any character
\s
matches whitespace
\S
matches any non-whitespace
*
repeats a character 0 or more times
*?
repeats a character 0 or more times(non-greedy)
+
repeats a character 1 or more times
+?
repeats a character 1 or more times(non-greedy)
[aeiou]
matches a single character in the listed set
[^XYZ]
matches a single character not in the listed set
[a-z0-9]
the set of characters can include a range
(
indicates where string extraction is to start
)
indicates where string extraction is to end
Greedy Matching
import re
x='From: Using the :character'
y=re.findall('^F.+:', x)
print (y)
Output:
['From: Using the :']
import re
x='From: Using the :character'
y=re.findall('^F.*:', x)
print (y)
Output:
['From: Using the :']
NON-Greedy Matching
import re
x='From: Using the :character'
y=re.findall('^F.+?:', x)
print (y)
Output:
['From:']
import re
x='From: Using the :character'
y=re.findall('^F.*:', x)
print (y)
Output:
['From:']
说明:在字符串'From:Using the :character' 中, 有两个: 号存在。 当要匹配以F开头,以: 号结尾的字符串时,GreedyMatching 会以Greedy 为原则找到尽可能长的匹配字符串。 而NON-Greedy Matching 不会像Greedy 那样去找尽可能长的串。
- [Python]Regular Expression Syntax
- python regular expression
- python regular expression basic
- Python Regular Expression
- Regular Expression Python
- regular expression matching --python
- [Python]Regular Expression Syntax(CHN)
- leetcode10 Regular Expression Matching @python
- 【LeetCode with Python】 Regular Expression Matching
- Python Regular Expression——简介
- Python re(regular expression operation) Module
- 10. Regular Expression Matching Leetcode Python
- [Leetcode]10. Regular Expression Matching @python
- Leetcode(python)--10.Regular Expression Matching
- regular expression
- Regular Expression
- regular expression
- Regular Expression
- ubuntu下安装程序的三种方法
- UIday1501:NSString的几种常用方法
- 使用BigDecimal进行精确数字运算
- OC-代码块的运用
- PPP拨号
- Python Regular Expression
- C++内存管理
- JAVA连接mysql
- swing设置图片为背景颜色
- Android之网络通信Volley框架用法
- Objective-C 【NSDictionary 文件操作(重点)&简写形式】
- poj解题报告——3069
- 归并排序c++实现
- eclipse 配置黑色主题