Mục Lục1. Regular Expression Căn Bản2. Ví dụ:Nội dung:1. Regular Expression Căn Bản
Ký Hiệu
Giải Thích
.
Bất kỳ ký tự nào
+
(...)
Showing posts with label Reg. Show all posts
Showing posts with label Reg. Show all posts
Regular Expression In Linux/Ubuntu/CentOS
Nội dung:
Tạo Regular Expression (RegEx) đơn giản
Sự khác nhau giữa RegEx căn bản và RegEx extended (Egrep)
Commands
1. Grep - Global RegEx: In ra dòng nếu tìm thấy mẫu (patterns)
Cú Pháp
Ví Dụ
Giải Thích
grep(...)
Học Python Qua Ví Dụ #019 Bài Tập - Regular Expression
Xem lý thuyết RegEx
ở đây
Xem format email ở đây
Ví dụ Extract Email:
Code:
'''
Yêu cầu:
Dùng RegEx để lấy ra tất cả các địa chỉ email từ chuỗi txt (kết quả đưa vào list)
'''
import re
txt = 'Hello from shubhamg+199630@gmail.com to pri.ya@yahoo.co.kr,pr_iya@yahoo.com,priya@yahoo to-ny@yahoo.com.vn about the meeting @2PM'
#regex ="[a-zA-Z0-9!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+"
regex ="[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+"
email = re.findall(regex, txt)
print(email)
Kết quả:
C:\python>python Demo.py
['shubhamg+199630@gmail.com', 'pri.ya@yahoo.co.kr', 'pr_iya@yahoo.com',
(...)
Học Python Qua Ví Dụ #018 - Regular Expression Trong Python
1. Regular Expression (RegEx) Funtions:
Match: Trả về kết quả THÀNH CÔNG hoặc None với mẫu trong chuỗi có
cờ tùy chọn
Search: Trả về kết quả THÀNH CÔNG nếu tìm thấy hoặc None nếu không
tìm thấy
(...)
Subscribe to:
Posts (Atom)