⊗pyPmREPT 55 of 128 menu

All pockets as a tuple in Python's search method

It is possible to obtain all pockets as a tuple. This is done using the groups method.

Let's see how to work with it. Let's say we have a string:

txt = '123 456 789'

Let's find the first row that matches the numbers. And then output all the pockets from it as a tuple:

res = re.search('(\d)(\d)(\d)', txt) print(res.groups()) # ('1', '2', '3')

Given a string containing a domain:

txt = 'http://domain.ru'

Get a tuple consisting of the protocol, domain name, and domain zone.

enru