Python provides simple string matching details and python string details.

Source: Internet
Author: User

Python provides simple string matching details and python string details.

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.

<Span style = "color: #333300;"> # import the 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 () </span>

Thank you for reading this article. I hope it will help you. Thank you for your support for this site!

Related Article

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.