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/337869.html below:

Cleaning strings with Regular Expressions

Cleaning strings with Regular Expressions Cleaning strings with Regular ExpressionsGary Wilson Jr gdub at ece.utexas.edu
Thu Sep 8 12:57:38 EDT 2005
sheffdog wrote:
> 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".

A regular expression to do what you want:
 >>> s = 'setAttr ".ftn" -type "string" /assets/chars/boya/geo/textures/lod1/ppbhat.tga";'
 >>> s = re.sub(r".*/(.*\.tga).*", r"\1", s)
 >>> s
'ppbhat.tga'

Is a regular expression the best solution?
That depends on what else you need to do with your data file.

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