Natural Language Understanding with Python by Deborah A. Dahl
Author:Deborah A. Dahl
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-06-27T00:00:00+00:00
General tips for using regular expressions
Regular expressions can easily become very complex and difficult to modify and debug. They can also easily fail to recognize some examples of what theyâre supposed to recognize and falsely recognize what theyâre not supposed to recognize. While it is tempting to try to match the regular expression so that it recognizes exactly what it is supposed to recognize and nothing else, this can make the expression so complicated that it is difficult to understand. Sometimes, it can be better to miss a few edge cases to keep the expression simple.
If we find that an existing regular expression is failing to find some expressions that we want to capture, or incorrectly finding expressions that we donât want to capture, it can sometimes be difficult to revise the existing expression without breaking some things that used to work. Here are a few tips that can make regular expressions easier to work with:
Write down what you want the regular expression to match first (such as any two consecutive uppercase alphabetic characters). This will be helpful in both clarifying what youâre trying to do as well as in helping catch any cases that you might have overlooked.
Break complex expressions into components and test each component independently before putting them together. Besides helping with debugging, the component expressions can potentially be reused in other complex expressions. We saw this in the first code block in the previous section with components such as street_name_re.
Use existing tested regular expressions for common expressions, for example, the Python datetime package (see https://docs.python.org/3/library/datetime.html), before trying to write your own regular expressions. They have been well tested over many years by many developers.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Computer Vision & Pattern Recognition | Expert Systems |
Intelligence & Semantics | Machine Theory |
Natural Language Processing | Neural Networks |
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8261)
Test-Driven Development with Java by Alan Mellor(6396)
Data Augmentation with Python by Duc Haba(6295)
Principles of Data Fabric by Sonia Mezzetta(6073)
Hadoop in Practice by Alex Holmes(5942)
Learn Blender Simulations the Right Way by Stephen Pearson(5932)
Microservices with Spring Boot 3 and Spring Cloud by Magnus Larsson(5818)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5787)
RPA Solution Architect's Handbook by Sachin Sahgal(5213)
Big Data Analysis with Python by Ivan Marin(5182)
Life 3.0: Being Human in the Age of Artificial Intelligence by Tegmark Max(5108)
The Infinite Retina by Robert Scoble Irena Cronin(4904)
Pretrain Vision and Large Language Models in Python by Emily Webber(4158)
Functional Programming in JavaScript by Mantyla Dan(4022)
The Age of Surveillance Capitalism by Shoshana Zuboff(3917)
Infrastructure as Code for Beginners by Russ McKendrick(3916)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3620)
Embracing Microservices Design by Ovais Mehboob Ahmed Khan Nabil Siddiqui and Timothy Oleson(3432)
Applied Machine Learning for Healthcare and Life Sciences Using AWS by Ujjwal Ratan(3405)
