How do I match . . . Thank you both very much!

plz_reply_to_group none at microsoft.com
Thu Jun 10 00:03:01 EDT 1999


Dang, those are both good ideas! Now that I have taken a little break
from what i was doing, I can see that I was not thinking too clearly
about what I was trying to do. I was thinking in terms of "regular
expressions", not strings! I was almost going to resort to reversing the
string, then matching the '/', clipping off the file name, then
reversing it again, or using a while loop to match each occurance. Both
seemed inelegant. 
 
Thanks!

Jeff Polaski



"Jeff P." wrote:
> 
> I've been messing with this for a little while now, but I can't get this
> to work. How do I match the last occurence of '\' in a string? I want to
> remove the file name from a url (e.g. news/breakingnews/981001b.html -->
> news/breakingnews/ ).
> 
> Here is the simplest version (that doesn't work). It matches the _first_
> backslash.
> 
> import regex
> 
> file_in = open( 'dir.txt', 'r+' )
> for line in file_in.readlines():
>         print regex.search( '/', line )
> 
> Thanks for any help!
> 
> Jeff P.





More information about the Python-list mailing list