Regular Expression Python

Source: Internet
Author: User

The following is a way to match the keyword from the results, but is not every time can be 100% accurate

Search_words_dict = {    "enteritis Ning": 0,"Vitamin Ad": 0,"gynecological daughter": 0,"Honeysuckle Dew": 0,"Raw vein Drink": 0,"Bone Thong paste": 0,"37 Injury Pills": 0,"Children's Cold granules": 0,}keys=Search_words_dict.keys () array_str=")| (". Join (keys) Array_str=". * (%s). *"%Array_str#array = ". *) | (. * ". Join (keys)#array = "(. *%s.*)"% arrayStrss ="compound women's and gold Peanuts Shandong Province vein Drink dew Chisang Shengmai drink children Cold granule injury Pills Gold Press more Nao that"pattern=re.compile (ARRAY_STR)Print("The content of the regular is:%s"%pattern)ifRe.search (Pattern, strss):Print(Re.search (pattern, strss))Else:    Print("So sorry")

The second way, this way, it's a lot more.

Search_words_dict = {    "enteritis Ning": 0,"Vitamin Ad": 0,"gynecological daughter": 0,"Honeysuckle Dew": 0,"Raw vein Drink": 0,"Bone Thong paste": 0,"37 Injury Pills": 0,"Children's Cold granules": 0,}keys=Search_words_dict.keys ()#array_str = ") | (". Join (keys)#array_str = ". * (%s). *"% array_str#pattern = re.compile (ARRAY_STR)Array =".*)| (.*". Join (keys) array="(. *%s.*)"%Arraypattern=re.compile (array) Strss="compound women's and gold peanut Shandong Province vein Drink dew Chisang children Cold granule injury Pills Gold Press more Nao that"Print("The content of the regular is:%s"%pattern)ifRe.search (Pattern, strss):Print(Re.search (pattern, strss))Else:    Print("So sorry")

From the result: the match is all

Regular Expression Python

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.