The group is identified by & quot; (& quot; and & quot;) & quot; metacharacters. & Quot; (& quot; and & quot;) & quot; many of them share the same meaning in mathematical expressions. they combine the expressions in them into a group.
The code is as follows:
Import re
Text='v10}renow.android.2.2.normal.1.alpha.apk? IMSI = 460029353813976 & MOBILE = & OLD_VERSION = renow. Android.2.1.Normal. 1. Alpha & CHANNELID = 3'
M = re. search (r "\ w + _ (renow. *) \. (apk | vir | ipa )\? IMSI = (\ d +) & MOBILE = & OLD_VERSION = (. *) & CHANNELID = (. *) ", text)
If m:
Print m. group (0), '\ n', m. group (1), '\ n', m. group (2), '\ n', m. group (3), '\ n', m. group (4), '\ n', m. group (5)
Else:
Print 'not match'
The following is a supplement:
Groups are identified by "(" and ")" metacharacters. "(" And ")" has a lot of the same meanings in mathematical expressions; they combine the expressions in them into a group. For example, you can use repeated delimiters, such as *, + ,?, And {m, n} to repeat the content in the group. for example, (AB) * matches zero or more duplicate "AB ".
Example: If no parentheses are introduced, add an expression as a group, which is group (0)
>>> Import re
>>> P = re. compile ('\ d-\ d ')
>>> M = p. match ('2-3-1 ')
>>> M. groups ()
()
>>> M. group ()
'2-3-1'
>>> M. group (1)
Traceback (most recent call last ):
File" ", Line 1, in
IndexError: no such group
If parentheses are introduced, you can divide the above expressions into three groups, as shown below:
>>> P = re. compile ('(\ d)-(\ d )')
>>> M = p. match ('1-2-3 ')
>>> M. group ()
'1-2-3'
>>> M. group (1)
'1'
>>> M. group (0, 2, 1)
('2-3-1 ', '2', '1 ')
You can also name each group. for example, you can name the first array first.
>>> P = re. compile ('(? P \ D)-(\ d )')
>>> M = p. match ('1-2-3 ')
>>> M. group (1)
'1'
>>> M. group ('first ')
'1'