程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

python_ re_ regular expression

編輯:Python

Regular expression patterns :

^ Match the beginning of the string
$ Match the end of the string
. Match any character , Except for line breaks
[...] Used to represent a set of characters , List... Separately :[amk] matching 'a','m' or 'k'
[^...] be not in [] The characters in :[^abc] Match except a,b,c Other characters .
re* matching 0 One or more expressions .
re+ matching 1 One or more expressions .
re? matching 0 Or 1 Fragments defined by the previous regular expression , Not greedy
[a|b] matching a or b
{n} matching n Time
(re) Group regular expressions and remember the matching text
\w Match alphanumeric and underline
\d Match any number , Equivalent to [0-9]
\D Match any non number
Greedy mode : As long as there are characters matching the pattern after the string, they will always match
Non greedy model : Add one more ?, Stop matching as long as the matching characters appear

Directly convert the matching result to dictionary mode , Easy to use :

 example : Id card 1102231990xxxxxxxx
import re
s = '1102231990xxxxxxxx'
res = re.search('(?P<province>\d{

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved