This article describes Python's detailed description of string matching. For more information, see the next article, for more information, see
Python for simple string matching
Since fields in specific formats need to be extracted from semi-structured text data, and data mining and analysis can be assisted, Matlab tools have been used for modeling structured data processing in the past, matlab is good at Matrix processing and structured data computing. Python has the same features as matlab: Concise syntax and rich libraries. it is a simple and easy-to-use language for algorithm simulation.
Python is relatively easy to get started with string matching, and has a mature String Processing library re for our use;
With the help of the re Library, matching can be completed in just two simple steps. for data analysis/algorithm workers, it is much easier:
Step 1: construct the regular expression mode and use the compile () function to generate a regular expression object.
Step 2: call the method and attribute of the in-expression object generated by Step 1 and return the matching result.
# Import regular expression matching module Py 3.0 import re text = "today is 01/04/2015, happy new year... "# Create a regular expression for date detepat = re. compile ('(\ d +)/(\ d +)') # Match and print the result = detepat. finditer (text) for m in result: print (m. group ())
The above is a detailed description of Python string matching. For more information, see other related articles in the first PHP community!