Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 15ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
r

re

Recently created Least recently created Recently updated Least recently updated

timmy / 使用 re 進行正規表示式匹配

Last active 6 hours ago pattern-matching python re regex text-processing validation

re 模組提供強大的正規表示式功能,可用於文字搜尋、字串處理與資料驗證,適用於日誌分析、表單驗證與文字解析等場景。

0 0 0 1
1 import re
2
3 # 定義正規表示式模式
4 pattern = r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b"
5
6 # 測試字串
7 text = "聯絡我們: support@example.com 或 visit@example.org"
8
9 # 搜尋第一個匹配的電子郵件
10 match = re.search(pattern, text)