Skip to Content
Python 技術手冊 第三版
book

Python 技術手冊 第三版

by lex Martelli, Anna Martelli Ravenscroft, Steve Holden
January 2018
Intermediate to advanced
856 pages
17h 17m
Chinese
GoTop Information, Inc.
Content preview from Python 技術手冊 第三版
291
9
正規表達式
正規表達式(regular expressions)讓你指定模式字串(pattern strings),
並執行搜尋和替換。正規表達式並不容易精通,但它們可以是處理文字的
強大工具。Python 透過內建的
re
模組提供豐富的正規表達式功能。
正規表達式和 re 模組
一個
正規表達式
regular expression
RE)是從代表一個模式(pattern
的字串建置出來的。透過 RE 的功能性,你能以該模式(pattern)檢視任
何的字串,看看字串的哪個部分匹配(pattern)該模式,如果有的話。
re
模組供應 Python RE 功能性。
compile
函式會從一個模式字串和選擇
性的旗標(flags)建置出一個 RE 物件。RE 物件的方法會在字串中尋找
RE 的匹配,或進行替換。
re
模組也對外提供了與 RE 物件的方法等效的函
式,但以 RE 的模式字串作為第一引數。
RE 可能很難精通,而本書的目的並不是教導它們,我們只涵蓋你可以
Python 中使用 RE 的方式。對於 RE 的一般性介紹,我們推薦 Jeffrey
Friedl 所著的
Mastering Regular Expressions
O
Reilly)。 Friedl 的書完整
涵蓋了 RE 的入門指南和進階主題。RE 的許多教學指南和參考也可以在
線上找到,包括線上文件中一個很棒的詳盡教程(
https://docs.python.org/3/
howto/regex.html
)。像是Pythex
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

利用 Python 进行数据分析(原书第2版)

利用 Python 进行数据分析(原书第2版)

Wes McKinney

Publisher Resources

ISBN: 9789864766819