Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses the re.search function

Shulou Source: shulou.com Published: 2022-06-01 02:32:27 09月19日 Update

This article will explain in detail how python uses the re.search function, Xiaobian feels quite practical, so share it with you as a reference, I hope you can gain something after reading this article.

re.search

The re.search function looks for pattern matches within the string, only until the first match is found and returns, if no match is found in the string, returns None.

import retext = "PythonTab.com is a good Python website"m = re.search(r'\Pyt(on)n\s', text)if m:print m.group(0), m.group(1)else:print 'not search'

The prototype of re.search is: re.search(pattern, string, flags)

Each parameter has the same meaning as re.match.

The difference between re.match and re.search: re.match matches only the beginning of the string, if the string does not match the regular expression at the beginning, the match fails, and the function returns None; while re.search matches the entire string until a match is found.

About "python how to use re.search function" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.

Tags: Functions characters strings articles more good practical content prototypes parameters meanings articles patterns rules knowledge expressions references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Xiaomi Redmi macOS OPPO Reno