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 6 2376
"sheffdog" <ma************ @gmail.com> wrote: setAttr ".ftn" -type "string" /assets/chars/ /boya/geo/textures/lod1/ppbhat.tga";
Can I do this in one line? os.path.basenam e("/assets/chars/.../lod1/ppbhat.tga")
'ppbhat.tga'
</F>
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.b asename(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
Using basename works, but leaves the extra stuff at the end.
Which would have to be removed with another line of code
I get this--> ppbhat.tga";
Thanks, for the idea though.
/\/\ason
"sheffdog" <ma************ @gmail.com> wrote: Using basename works, but leaves the extra stuff at the end. Which would have to be removed with another line of code
I get this--> ppbhat.tga";
if you're trying to parse Maya files, maybe you should start
by writing a simple Maya parser, and use that to extract the
relevant strings, *before* passing them to os.path.baselin e?
</F>
Good Idea I'll try that!
Thanks for your assistance.
/\/\
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lawrence |
last post by:
"Garp" <garp7@no7.blueyonder.co.uk> wrote in message news:<_vpuc.1424$j_3.13346038@news-text.cableinet.net>...
> "lawrence" <lkrubner@geocities.com> wrote in message
> news:da7e68e8.0405300907.3c8eabf7@posting.google.com...
> > This reg ex will find me any block of strings 40 or more characters in
> > length without a white space, yes?
> >
> > {40}
> >
> >
> > To get it to include tabs and newlines, do I to this?
|
by: Muumac |
last post by:
I have problem with large textfiles! When I load over 4MB xml and then
try to preg_match something in this I get always FALSE!
I have <File>....</File> tags in XML. Between tags is files contents
BASE64 encoded! When xml contains only one big over 4MB file in it,
preg_match and preg_match_all doesnt find it! When included file size is
nelow 4MB, preg functions works perfectly!
But PHP manual says that there is no size limitations to...
|
by: Ravi |
last post by:
Hi,
I have about 200GB of data that I need to go through and extract the
common first part of a line. Something like this.
>>>a = "abcdefghijklmnopqrstuvwxyz"
>>>b = "abcdefghijklmnopBHLHT"
>>>c = extract(a,b)
>>>print c
"abcdefghijklmnop"
|
by: Maurice LING |
last post by:
I'm trying to toy around with PLY (python lex-yacc) by David Beazley
from University of Chicago and realized that the lex module uses python
raw strings. What are python raw strings and how are they different from
regular strings? I've tried to look up in the python documentation but
it just vaguely brushes through by saying that python raw strings are
prefixed with "r" or "R".
In PLY, "+" is "r'\+'" but "-" is "r'-'", why is there an...
|
by: cleo |
last post by:
I'm experimenting with Regular Expressions and Windows Forms.
Frequently I want a value to be either a valid pattern or empty. For
example a Zip code must be 5 digits or may be empty. I know that I can use
the Regular Expression "\d{5}" to test for exactly 5 digits. How can I add
the option for the string to be empty or must I always test the value before
calling the Regular Expression?
Thanks
| |
by: Fuzzyman |
last post by:
Hello all,
Can someone confirm that compiled regular expressions from ascii
strings will always (and safely) yield unicode values when matched
against unicode strings ?
I've tested it and it works - but can someone confirm that this is
consistent and safe ? (No lurking encode errors - I assume it is only a
decode that is done, in which case is it safe on a system that has a
non-ascii compatible default encoding ? OTOH it would seem to...
|
by: plahey |
last post by:
I thought I understood raw strings, then I got bitten by this:
x=r'c:\blah\'
which is illegal! I thought that \ had no special meanning in a raw
string so why can't it be the last character?
making me do:
x=r'c:\blah' '\\'
|
by: Jesper Stocholm |
last post by:
I have developed a data-cleaner that extracts some data from a database,
cleans it for illegal/unwanted data and writes it to a CSV-fil for later
insertion to a SQL Server 2000 database. My problem is that it performs
like an old, limb man :o(
The method is:
public static StringBuilder RemoveChars(StringBuilder dataToClean_, string illegalChars_)
{
// only try to remove chars if there is data to clean
|
by: Matthew Warren |
last post by:
Hi,
I would expect this to work,
rawstring=r'some things\new things\some other things\'
But it fails as the last backslash escapes the single quote.
...although writing this I think I have solved my own problem. Is \' the
only thing escaped in a raw string so you can place ' in a raw string?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |