[Tutor] Question on regular expressions
alan.gauld at btinternet.com
Tue Feb 12 19:40:06 CET 2013
On 12/02/13 17:43, Marcin Mleczko wrote:
> but I am interested only in the second part between the 2nd "start" and
> the "end": "start AnotherArbitraryAmountOfText end"
> What would be best, most clever way to search for that?
best and clever are not always the same.
The simplest way if its a fixed string is just use the string split()
method... being more 'clever' you could use the re.split() method to
handle non-constant strings. Being even more clever you can define regex
of increasing complexity to match the Nth appearance of a pattern. These
kinds of regex are very easy to get wrong so you have to be very clever
to get them right.
Author of the Learn to Program web site
More information about the Tutor