Reg Expression - Get position of >
Jorgen Grahn
grahn+nntp at snipabacken.se
Wed Nov 26 13:23:00 EST 2008
On Wed, 26 Nov 2008 01:48:59 -0800 (PST), M_H <heyer.mario at googlemail.com> wrote:
> On Nov 25, 11:06 pm, r <rt8... at gmail.com> wrote:
>> On Nov 25, 4:33 pm, Jorgen Grahn <grahn+n... at snipabacken.se> wrote:
...
>> > Depends on if you have an irrational fear of REs or not ... I agree
>> > that REs are overused for things which are better done with split, but
>> > in this case I think an RE would be clearer.
>>
>> > >>> re.sub('.*>', '', 'dkjk>dj>>>>dd')
...
> I want to have the end-position of the mimetype tag (position as
> mystr.find('>') returns, so I can use the number for a loop)
> However, I can't use just the '>' because the character > could also
> be in the string of mimetype (I know, actually not in mimetype, but
> let's assume it).
> So that is why the filter shall be bulletproof and check for '">' -
> with possible spaces between both characters.
OK. I am too tired to think it through, but if you need to handle
nesting brackets or escaped brackets (e.g. ignore brackets inside
double-quoted strings) then an RE is not the best solution.
/Jorgen
--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!
More information about the Python-list
mailing list