tailieunhanh - Dive Into Python-Chapter 7. Regular Expressions

Tham khảo tài liệu 'dive into python-chapter 7. regular expressions', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 7. Regular Expressions Regular expressions are a powerful and standardized way of searching replacing and parsing text with complex patterns of characters. If you ve used regular expressions in other languages like Perl the syntax will be very familiar and you get by just reading the summary of the re module to get an overview of the available functions and their arguments. . Diving In Strings have methods for searching index find and count replacing replace and parsing split but they are limited to the simplest of cases. The search methods look for a single hard-coded substring and they are always case-sensitive. To do case-insensitive searches of a string s you must call s . lower or s. upper and make sure your search strings are the appropriate case to match. The replace and split methods have the same limitations. If what you re trying to do can be accomplished with string functions you should use them. They re fast and simple and easy to read and there s a lot to be said for fast simple readable code. But if you find yourself using a lot of different string functions with i f statements to handle special cases or if you re combining them with split and join and list comprehensions in weird unreadable ways you may need to move up to regular expressions. Although the regular expression syntax is tight and unlike normal code the result can end up being more readable than a hand-rolled solution that uses a long chain of string functions. There are even ways of embedding comments within regular expressions to make them practically self-documenting. . Case Study Street Addresses This series of examples was inspired by a real-life problem I had in my day job several years ago when I needed to scrub and standardize street addresses exported from a legacy system before importing them into a newer system. See I don t just make this stuff up it s actually useful. This example shows how I approached the problem. Example . Matching at the End of a String s

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.