正則表達式基本規則

正則表達式基本規則

1:正則表達式在實際中的一個經典應用是識別郵箱地址。雖然不一樣郵箱服務器的郵箱地址的具體規則不盡相同,可是咱們仍是能夠建立幾條通用規則。html

這裏寫圖片描述

把上面的規則鏈接起來,就得到了完整的正則表達式。python

[A-Za-z0-9\._+]+@[A-Za-z]+\.(com|org|edu|net)

2:正則表達式經常使用符號
這裏寫圖片描述
3:簡單示例
a:注意代碼中的正則表達式web

# coding=utf-8
""" @author: jiajiknag 程序功能:獲取網頁上的圖片,且打印出圖片的相對路徑 待抓取的網頁是 http://www.pythonscraping.com/pages/page3.html """
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
# urlopen 用來打開並讀取一個從網絡獲取的遠程對象
html = urlopen("http://www.pythonscraping.com/pages/page3.html")
bs0j = BeautifulSoup(html)
images = bs0j.findAll("img",{"src":re.compile("\.\./img\/gifts/img.*\.jpg")})
for image in images:
    print(image["src"])

b:結果
這裏寫圖片描述正則表達式

4:在線正則表達式
在線檢查本身寫的正則表達式是否正確:https://www.regexpal.com/api

注:
不全面,若有關於正則表達式的會繼續更新,博主只是用來做爲本身的電子筆記之後方便查閱罷了!!!服務器