A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2005-September/341731.html below:

Cleaning strings with Regular Expressions

Cleaning strings with Regular ExpressionsLarry Bates larry.bates at websafe.com
Tue Sep 6 17:04:24 EDT 2005
May not be what you are looking for, but this works:

import os
s='setAttr ".ftn" -type "string" ' \
  '/assets/chars/boya/geo/textures/lod1/ppbhat.tga";'
fname=os.path.basename(s.split()[-1])


BTW-It does depend on the file/path being the last item
on the line.

Larry Bates


sheffdog wrote:
> Hello,
> 
>  I often find myself cleaning up strings like the following:
> 
>     setAttr ".ftn" -type "string" /assets/chars/
>     /boya/geo/textures/lod1/ppbhat.tga";
> 
> Using regular expressions, the best I can do so far is using the re.sub
> command but it still takes two lines. Can I do this in one line? Or
> should I be approaching this differently? All I want to end up with is
> the file name "ppbhat.tga".
> 
> Python Code:
> lines[indexC]=re.sub("[\s,\S,]*/", "", lines[indexC])
> lines[indexC]=re.sub(".tga[\s,\S,]*", ".tga", lines[indexC])
> 
> Thanks for your time,
> 
> /\/\ason S
> 

More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4