Nếu bạn có nhiều cài đặt Python trên Windows và muốn tìm tất cả chúng, bạn có thể làm như vậy với dấu nhắc lệnh CMD hoặc Powershell. Lưu ý rằng các tìm kiếm có thể khá dài
cmd
dir site.py /s
Kết quả của tôi
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
PowerShell
C:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force
Kết quả của tôi
C:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force
Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/16/2017 7:38 PM 19168 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/7/2020 11:16 PM 21963 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 6/28/2021 4:06 PM 22207 site.py
Mac
Đối với người dùng Mac, đó là
ls -l /usr/bin/python*
Viết bởi Nat Dunn. Theo dõi Nat trên Twitter
Những bài viết liên quan
- Sửa thời gian WebVTT bằng Python
- Sử dụng Python để chuyển đổi hình ảnh sang WEBP
- Ký hiệu khoa học trong Python
- Hiểu biến __main__ của Python
- Chuyển đổi các tab hàng đầu thành không gian bằng Python
- pow[x, y, z] hiệu quả hơn x**y % z và các tùy chọn khác
- Một mô hình Python cho các trận đấu bóng bàn
- Chuyển đổi hàng loạt tệp Python sang tệp IPython Notebook [chuyển đổi py sang ipynb]
- Ngày của Python. strftime[] chậm hơn str[], tách, giải nén và nối?
- Bài tập lập trình Python cơ bản. Một Penny nhân đôi mỗi ngày
- Từ điển hai chiều trong Python
- Cách tìm tất cả các cài đặt Python của bạn trên Windows [và Mac] [bài viết này]
- Liên kết tệp Python với IDLE
- Thay đổi Khoảng thời gian tự động lưu mặc định trong JupyterLab
- con trăn. isdigit[] so với. là thập phân[]
- Giải thích về đồng hồ Python
- Mô-đun hằng số màu Python
- Đã vượt quá độ sâu đệ quy tối đa khi gọi một đối tượng Python
- Khi nào nên sử dụng Phương thức tĩnh trong Python?
- Cuối cùng, một trường hợp sử dụng cho cuối cùng – Xử lý ngoại lệ Python
- Tạo Trình trang trí email bằng Python và AWS
- Thử thách mã hóa Python. Hai người có cùng ngày sinh
- Cách tạo mô phỏng đơn giản bằng Python – Dữ liệu số
- Phỏng đoán Collatz trong Python
- Tập lệnh Python đơn giản để trích xuất văn bản từ tệp SRT
- Môi trường ảo Python với venv
- Ánh xạ python sang Python 3 trên máy Mac của bạn
- Cách đặt IDLE làm Trình chỉnh sửa mặc định cho các tệp Python trên Windows
- Cách thực hiện phép gán toán tử ternary trong Python
- Cách chuyển đổi giây sang năm bằng Python
- Cách tạo gói Python
- Cách đọc tệp bằng Python
- Cách kiểm tra hệ điều hành bằng Python
- Cách sử dụng enumerate[] để in danh sách được đánh số bằng Python
- Cách nối lặp lại nhiều lần vào một chuỗi trong Python
- Kiểm tra Sơ đồ trang web của bạn để tìm các Liên kết bị hỏng bằng Python
- Cách thực hiện Bài tập đồng thời trong Python
- Visual Studio Code - Mở tệp bằng Python open[]
- Cách cắt chuỗi trong Python
- Cách Python tìm các mô-đun đã nhập
- Cách hợp nhất từ điển trong Python
- Cách lập chỉ mục chuỗi trong Python
- Cách tạo Tuple trong Python
Bạn đang tìm cách cải thiện kỹ năng Python của mình?
Khi tôi lần đầu tiên tìm hiểu về biểu thức chính quy, tôi đã không thực sự đánh giá cao sức mạnh của chúng. Nhưng có một lý do khiến các biểu thức chính quy tồn tại sau bảy thập kỷ gián đoạn công nghệ. các lập trình viên hiểu các biểu thức chính quy có lợi thế lớn khi làm việc với dữ liệu văn bản. Họ có thể viết trong một dòng mã mà người khác phải mất hàng tá
Bài viết này là tất cả về phương thức
ls -l /usr/bin/python*
7 của thư viện ls -l /usr/bin/python*
8 của Python. Phương thức ls -l /usr/bin/python*
7 là cách cơ bản nhất để sử dụng các biểu thức chính quy trong Python. Nếu bạn muốn làm chủ chúng, hãy bắt đầu từ đâyPython Regex Findall[]
Xem video này trên YouTube
bài viết liên quan. Python Regex Superpower – Hướng dẫn cơ bản
Bạn có muốn làm chủ siêu năng lực regex không? . [1] nghiên cứu một chương sách, [2] giải câu đố mật mã và [3] xem video về chương giáo dục
Vậy phương pháp
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 hoạt động như thế nào?
Phương thức findall[] hoạt động như thế nào trong Python?
Phương pháp
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 quét
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''1 từ trái sang phải, tìm kiếm tất cả các kết quả khớp không chồng chéo của
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''2. Nó trả về một danh sách các chuỗi theo thứ tự phù hợp khi quét chuỗi từ trái sang phải
Sự chỉ rõ
________số 8Phương thức
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 có tối đa ba đối số
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
2. mẫu biểu thức chính quy mà bạn muốn đối sánhimport re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
1. chuỗi mà bạn muốn tìm kiếm mẫuimport re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
6 [đối số tùy chọn]. một công cụ sửa đổi nâng cao hơn cho phép bạn tùy chỉnh hành vi của chức năng. Bạn muốn biết cách sử dụng những lá cờ đó?
Chúng tôi sẽ xem xét từng người trong số họ chi tiết hơn
Giá trị trả về
Phương thức
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 trả về một danh sách các chuỗi. Mỗi phần tử chuỗi là một chuỗi con phù hợp của đối số chuỗi
Hãy kiểm tra một vài ví dụ
ví dụ lại. tìm tất cả []
Nhập mô-đun
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''8 và tạo chuỗi văn bản để tìm kiếm các mẫu biểu thức chính quy
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
Giả sử, bạn muốn tìm kiếm văn bản cho chuỗi
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''9
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
5Đối số đầu tiên là mẫu bạn tìm kiếm. Trong trường hợp của chúng tôi, đó là chuỗi
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''9. Đối số thứ hai là văn bản được phân tích. Bạn đã lưu trữ chuỗi nhiều dòng trong biến
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
51—vì vậy bạn coi đây là đối số thứ hai. Bạn không cần xác định đối số thứ ba tùy chọn import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''6 của phương thức
ls -l /usr/bin/python*
7 vì bạn thấy ổn với hành vi mặc định trong trường hợp nàyCũng lưu ý rằng hàm
ls -l /usr/bin/python*
7 trả về danh sách tất cả các chuỗi con phù hợp. Trong trường hợp này, điều này có thể không quá hữu ích vì chúng tôi chỉ tìm kiếm một chuỗi chính xác. Nhưng nếu chúng ta tìm kiếm các mẫu phức tạp hơn, điều này thực sự có thể rất hữu íchC:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
9Regex
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
55 khớp với tất cả các từ bắt đầu bằng ký tự C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
56Bạn có thể yêu cầu. tại sao phải đính kèm biểu thức chính quy với một
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
57 ở đầu và cuối? . Bạn có thể định nghĩa một từ là một chuỗi các ký tự không phải là ký tự khoảng trắng hoặc các dấu phân cách khác, chẳng hạn như C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
58Trong ví dụ trước, bạn cần thoát lại ký tự ranh giới
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
59 vì trong một chuỗi Python, ý nghĩa mặc định của chuỗi ký tự C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
59 là ký tự dấu gạch chéo ngượcĐâu là sự khác biệt giữa re. findall[] và lại. Tìm kiếm[]?
Có hai điểm khác biệt giữa phương pháp
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 và
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
92
92 trả về một đối tượng khớp trong khiC:\>dir site.py /s Volume in drive C is OS Volume Serial Number is 4814-EF41 Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib 09/16/2017 07:38 PM 19,168 site.py 1 File[s] 19,168 bytes Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib 09/07/2020 11:16 PM 21,963 site.py 1 File[s] 21,963 bytes Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib 06/28/2021 04:06 PM 22,207 site.py 1 File[s] 22,207 bytes Total Files Listed: 3 File[s] 63,338 bytes 0 Dir[s] 570,192,752,640 bytes free
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
0 trả về danh sách các chuỗi khớp
92 chỉ trả về kết quả khớp đầu tiên trong chuỗi trong khiC:\>dir site.py /s Volume in drive C is OS Volume Serial Number is 4814-EF41 Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib 09/16/2017 07:38 PM 19,168 site.py 1 File[s] 19,168 bytes Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib 09/07/2020 11:16 PM 21,963 site.py 1 File[s] 21,963 bytes Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib 06/28/2021 04:06 PM 22,207 site.py 1 File[s] 22,207 bytes Total Files Listed: 3 File[s] 63,338 bytes 0 Dir[s] 570,192,752,640 bytes free
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
0 trả về tất cả kết quả khớp trong chuỗi
Cả hai có thể được nhìn thấy trong ví dụ sau
C:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force
Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/16/2017 7:38 PM 19168 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/7/2020 11:16 PM 21963 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 6/28/2021 4:06 PM 22207 site.py
2Chuỗi
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
97 chứa hai lần xuất hiện của C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
98. Phương thức C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
99 chỉ trả về một đối tượng khớp của lần xuất hiện đầu tiên. Phương thức ls -l /usr/bin/python*
7 trả về danh sách tất cả các lần xuất hiệnĐâu là sự khác biệt giữa re. findall[] và lại. cuộc thi đấu[]?
Có hai điểm khác biệt giữa phương pháp
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 và
C:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force
Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/16/2017 7:38 PM 19168 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/7/2020 11:16 PM 21963 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 6/28/2021 4:06 PM 22207 site.py
22
22 trả về một đối tượng khớp trong khiC:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/16/2017 7:38 PM 19168 site.py Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/7/2020 11:16 PM 21963 site.py Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 6/28/2021 4:06 PM 22207 site.py
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
0 trả về danh sách các chuỗi khớp
22 chỉ trả về kết quả khớp đầu tiên trong chuỗi—và chỉ ở phần đầu—trong khiC:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/16/2017 7:38 PM 19168 site.py Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/7/2020 11:16 PM 21963 site.py Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 6/28/2021 4:06 PM 22207 site.py
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''
0 trả về tất cả kết quả khớp trong chuỗi
Cả hai có thể được nhìn thấy trong ví dụ sau
ls -l /usr/bin/python*
2Chuỗi
C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
97 chứa hai lần xuất hiện của C:\>dir site.py /s
Volume in drive C is OS
Volume Serial Number is 4814-EF41
Directory of C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
09/16/2017 07:38 PM 19,168 site.py
1 File[s] 19,168 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
09/07/2020 11:16 PM 21,963 site.py
1 File[s] 21,963 bytes
Directory of C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
06/28/2021 04:06 PM 22,207 site.py
1 File[s] 22,207 bytes
Total Files Listed:
3 File[s] 63,338 bytes
0 Dir[s] 570,192,752,640 bytes free
98. Phương thức C:\> Get-ChildItem -Path C:\ -Filter site.py -Recurse -ErrorAction SilentlyContinue -Force
Directory: C:\Program Files\MySQL\MySQL Workbench 8.0 CE\python\lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/16/2017 7:38 PM 19168 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python38\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/7/2020 11:16 PM 21963 site.py
Directory: C:\Users\ndunn\AppData\Local\Programs\Python\Python39\Lib
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 6/28/2021 4:06 PM 22207 site.py
29 chỉ trả về một đối tượng khớp của lần xuất hiện đầu tiên. Phương thức ls -l /usr/bin/python*
7 trả về danh sách tất cả các lần xuất hiệnĐi đâu từ đây?
Bài viết này đã giới thiệu phương thức
import re text = ''' Ha! let me see her: out, alas! he's cold: Her blood is settled, and her joints are stiff; Life and these lips have long been separated: Death lies on her like an untimely frost Upon the sweetest flower of all the field. '''0 cố gắng khớp tất cả các lần xuất hiện của mẫu biểu thức chính quy trong một chuỗi đã cho—và trả về danh sách tất cả các kết quả khớp dưới dạng chuỗi
Python đang phát triển nhanh chóng và thế giới ngày càng bị chia thành hai lớp. những người hiểu mã hóa và những người không. Loại thứ hai sẽ gặp khó khăn ngày càng lớn hơn khi tham gia vào kỷ nguyên áp dụng và thâm nhập ồ ạt nội dung số. Bạn có muốn nâng cao kỹ năng Python của mình hàng ngày mà không cần đầu tư nhiều thời gian không?
Sau đó tham gia danh sách email “Coffee Break Python” của tôi gồm hàng chục nghìn lập trình viên đầy tham vọng
Khóa học Python Regex
Các kỹ sư của Google là những bậc thầy về biểu thức chính quy. Công cụ tìm kiếm Google là một công cụ xử lý văn bản khổng lồ trích xuất giá trị từ hàng nghìn tỷ trang web.
Các kỹ sư của Facebook là những bậc thầy về biểu thức chính quy. Các mạng xã hội như Facebook, WhatsApp và Instagram kết nối con người qua tin nhắn văn bản.
Các kỹ sư của Amazon là những bậc thầy về biểu thức chính quy. Gã khổng lồ thương mại điện tử vận chuyển sản phẩm dựa trên mô tả sản phẩm bằng văn bản. Biểu thức chính quy thống trị trò chơi khi xử lý văn bản đáp ứng khoa học máy tính.
Nếu bạn cũng muốn trở thành bậc thầy về biểu thức chính quy, hãy xem khóa học Python regex toàn diện nhất hành tinh
Chris
Trong khi làm việc với tư cách là một nhà nghiên cứu trong các hệ thống phân tán, Dr. Christian Mayer tìm thấy tình yêu của mình với việc dạy sinh viên khoa học máy tính
Để giúp sinh viên đạt được mức độ thành công Python cao hơn, anh ấy đã thành lập trang web giáo dục lập trình Finxter. com. Ông là tác giả của cuốn sách lập trình nổi tiếng Python One-Liners [NoStarch 2020], đồng tác giả của loạt sách tự xuất bản Coffee Break Python, người đam mê khoa học máy tính, cộng tác viên tự do và chủ sở hữu của một trong 10 blog Python lớn nhất thế giới
Niềm đam mê của anh ấy là viết, đọc và mã hóa. Nhưng niềm đam mê lớn nhất của anh ấy là phục vụ các lập trình viên đầy tham vọng thông qua Finxter và giúp họ nâng cao kỹ năng của mình. Bạn có thể tham gia học viện email miễn phí của anh ấy tại đây