473,394 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Extract value from a attribute in a string


Hello,

I am looking for some help in reading a large text tile and extracting
a value from an attribute? so I would need to find name=foo and
extract just the value foo which can be at any location in the string.
The attribute name will be in almost each line.

Thank you for any suggestions.
Jan 23 '08 #1
2 1913
En Tue, 22 Jan 2008 23:45:22 -0200, <in*****@sl.comescribió:
I am looking for some help in reading a large text tile and extracting
a value from an attribute? so I would need to find name=foo and
extract just the value foo which can be at any location in the string.
The attribute name will be in almost each line.
In this case a regular expression may be the right tool. See
http://docs.python.org/lib/module-re.html

pyimport re
pytext = """ok name=foo
.... in this line name=bar but
.... here you get name = another thing
.... is this what you want?"""
pyfor match in re.finditer(r"name\s*=\s*(\S+)", text):
.... print match.group(1)
....
foo
bar
another

--
Gabriel Genellina

Jan 23 '08 #2
On Wed, 23 Jan 2008 01:13:31 -0200, "Gabriel Genellina"
<ga*******@yahoo.com.arwrote:
>En Tue, 22 Jan 2008 23:45:22 -0200, <in*****@sl.comescribió:
>I am looking for some help in reading a large text tile and extracting
a value from an attribute? so I would need to find name=foo and
extract just the value foo which can be at any location in the string.
The attribute name will be in almost each line.

In this case a regular expression may be the right tool. See
http://docs.python.org/lib/module-re.html

pyimport re
pytext = """ok name=foo
... in this line name=bar but
... here you get name = another thing
... is this what you want?"""
pyfor match in re.finditer(r"name\s*=\s*(\S+)", text):
... print match.group(1)
...
foo
bar
another
Thank you very much.
Jan 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Stefan Franke | last post by:
Hi, I've got the following simple XSLT stylesheet, that lists all the values of the elements of any given XML file. <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0"...
2
by: RichardHatcher.com | last post by:
I am writing C code using xpath to extract some data from a XML document. The file uses namespaces, but the name spaces are all listed in the root node of the file as attributes. I want to...
1
by: steveyjg | last post by:
I want to extract the following data from a retrieved html file and store the information as strings. 'get the text of "title" <h1 id="test_title">title</h1> 'get the contents of the value...
6
by: BlackLibrary | last post by:
The title probably tells it all. I'm a VB6 going to C# and trying to take a task I can do easily in VB6 and do it in C#.NET. I can really use some help and any pointers you can share. Below is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.