MyTetra Share
Делитесь знаниями!
match.start / match.end
Время создания: 31.08.2017 21:00
Текстовые метки: code
Раздел: Python - Modules - re - special characters
Запись: xintrea/mytetra_db_mcold/master/base/15028782125gccxn09d0/text.html на raw.githubusercontent.com

match.start([group])

match.end([group])

Return the indices of the start and end of the substring matched by group;group defaults to zero (meaning the whole matched substring). Return -1 ifgroup exists but did not contribute to the match. For a match object m, and a group g that did contribute to the match, the substring matched by group g(equivalent to m.group(g)) is

m.string[m.start(g):m.end(g)]

Note that m.start(group) will equal m.end(group) if group matched a null string. For example, after m = re.search('b(c?)', 'cba')m.start(0) is 1, m.end(0) is 2, m.start(1) and m.end(1) are both 2, and m.start(2)raises an IndexError exception.

An example that will remove remove_this from email addresses:

>>>

email = "tony@tiremove_thisger.net"
m = re.search("remove_this", email)
email[:m.start()] + email[m.end():]


Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования