Mastering Python Regular Expressions by 2014

Mastering Python Regular Expressions by 2014

Author:2014
Language: eng
Format: mobi
Publisher: Packt Publishing


If there are groups that don't match, then -1 is returned:

>>> math = pattern.search("Hello⇢") >>> match..start(2) -1

end([group])

The end operation behaves exactly the same as start, except that it returns the end of the substring matched by the group:

>>> pattern = re.compile(r"(?P<first>\w+) (?P<second>\w+)?") >>> match = pattern.search("Hello⇢") >>> match.end (1) 5

span([group])

It's an operation that gives you a tuple with the values from start and end. This operation is often used in text editors to locate and highlight a search. The following code is an example of this operation:

>>> pattern = re.compile(r"(?P<first>\w+) (?P<second>\w+)?") >>> match = pattern.search("Hello⇢") >>> match.span(1) (0, 5)



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.