Python string matching

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.