Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Python find all the substrings matched by regular expressions in a string

Shulou Source: shulou.com Published: 2022-06-01 01:33:26 09月29日 Update

Most people do not quite understand the knowledge points of this article "how to find all the substrings matched by regular expressions in a string", so the editor summarizes the following contents for you. The content is detailed, the steps are clear, and it has a certain reference value. I hope you can get something after reading this article. Let's take a look at this article entitled "how Python finds all the substrings that regular expressions match in a string."

Re.finditer

Similar to findall, all the substrings matched by the regular expression are found in the string and returned as an iterator.

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

Parameters:

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. Example

Import re

It = re.finditer (r "\ d +", "12a32bc43jf3")

For match in it:

Print (match.group ())

Output result:

1232 43 3 above is about the content of this article on "how Python finds all the substrings matched by regular expressions in a string". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Rules expressions characters strings content parameters articles knowledge articles values sizes most examples that is ways more flags steps knowledge points results Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux macOS Redmi Shulou Tech Info