Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the syntax of Python3's re.search function?

Shulou Source: shulou.com Published: 2022-06-01 01:33:28 10月02日 Update

In this article Xiaobian for you to introduce in detail "what is the syntax of Python3's re.search function", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the syntax of Python3's re.search function" can help you solve your doubts.

Re.search method

Re.search scans the entire string and returns the first successful match.

Function syntax:

Re.search (pattern, string, flags=0)

Function parameter description:

Parameter describes the string to be matched by the regular expression string that pattern matches. Flags flag bit, which is used to control how regular expressions are matched, such as case sensitivity, multi-line matching, and so on. See: regular expression modifier-optional Fla

If the match succeeds, the re.search method returns a matching object, otherwise it returns None.

We can use the group (num) or groups () match object function to get the matching expression.

The match object method describes the string of the entire expression that group (num=0) matches, and group () can enter more than one group number at a time, in which case it returns a tuple containing the values corresponding to those groups. Groups () returns a tuple containing all the team strings, from 1 to the contained group number. Example

#! / usr/bin/python3

Import re

Print (re.search ('www',' www.runoob.com'). Span ()) # matches at the starting position

Print (re.search ('com',' www.runoob.com'). Span ()) # does not match at the starting position

The output of the above instance is as follows:

(0,3) (11,14) read here, this article "what is the syntax of Python3's re.search function" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it to understand it. If you want to know more about related articles, you are welcome to follow the industry information channel.

Tags: Functions expressions grammars characters strings objects articles methods regular success position content parameters instances groups flags start proper multiple size Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple OPPO Reno Microsoft Docker MariaDB