Python Regular expression matches multiple keywords simultaneously (multiple keyword matches)

Source: Internet
Author: User

Many articles have been turned over the internet ... Actually not a useful one. I found a Java one, but Java's regular expressions are a bit different from Python's.

The article in Java is "[keywd1]| [keywod2]| [KEYWD3] "mode to match, this is not in the PY, [] will match [] any one of the words.

In Python, it should be "KEYWD1|KEYWD2|KEYWD3" on the line.

Then I personally like to use Re.findall directly () such a parameter is to match the character pattern, and the other is to match the text. More convenient, can not control those search,march, what.

One more thing. Parameter sequencing for regular expression matching: Re.findall (pattern, string[, flags]) # [, Flags] is an optional argument, starting with the first few characters

Python Regular expression matches multiple keywords simultaneously (multiple keyword matches)

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.