Linux, Python

RegularExpression(正則表達式)使用教學 -如何正確匹配字符串 – Python基礎

. – Any Character Except New Line
\d – Digit (0-9)
\D – Not a Digit(0-9)
\w – Word Character (a-z, A-Z, 0-9, _)
\W – Not a Word Character
\s – Whitespace (space, tab, newline)
\S – Not Whitespace (space, tab, newline)

\b – Word Boundary
\B – Not a Word Boundary
^ – Beginning of a String
$ – End of a String

[] – Mathes Characters in brackets
[^ ] – Matches Characters NOT in bracket
| – Either Or
( ) – Group

Quantifiers:
* – 0 or More
+ – 1 or More
? – 0 or One
{3} – Exact Number
{3,4} – Range of Numbers (Minimum, Maximum)

import re

text_to_search = ”’
abcdefghijklmnopqurtuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
1234567890
Ha HaHa
Meta Characters(need to be escaped):
. ^ $ * + ? { } [ ] \ | ( )
http://v2rayz.me


321-555-4321
123.555.12342343
123*555*1234234234
800-555-123454554654
900-555-1234332423


Mr Smith
Ms Davis
Mrs. Robinson
Mr. Ferrari JR.
Mr. T

[email protected]
[email protected]
[email protected]
[email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *