473,385 Members | 1,396 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,385 software developers and data experts.

Extracting text from alphanumeric strings

Hi There.

I'm trying to write a code that reads the filenames of objects of the form "gal_z7.25.sae" and "gal_z0.02563.sae" and stores the decimal digit parts ONLY to a list.

So far I have the following:
Expand|Select|Wrap|Line Numbers
  1. import glob
  2. import sys, os
  3.  
  4. #Open folder with files
  5. filelist = glob.glob("/home/clemence/Desktop/testing/*.sae")
  6.  
printing filelist gives me the following:

/home/clemence/Desktop/testing/gal_z0.275.sae'

And each item in filelist contains the numbers I need. All I need is a way of ignoring the text and taking only the numbers into another list.

Please help
Jul 22 '14 #1
1 1426
bvdet
2,851 Expert Mod 2GB
This can be done with a regular expression.
Expand|Select|Wrap|Line Numbers
  1. >>> results = ["gal_z7.25.sae", "gal_z0.02563.sae"]
  2. >>> import re
  3. >>> patt = re.compile(r"[^0-9.]+([0-9]+.[0-9]+)")
  4. >>> for item in results:
  5. ...     print patt.match(item).group(1)
  6. ...     
  7. 7.25
  8. 0.02563
  9. >>> 
Jul 22 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: BGP | last post by:
I am working on a WIN32 API app using devc++4992 that will accept Dow Jones/NASDAQ/etc. stock prices as input, parse them, and do things with it. The user can just cut and paste back prices into a...
4
by: Jay Nesbitt | last post by:
Is there a quick way to extract tokens from a string of text? I know Java provides a StringTokenizer class to do this. Is there something similar in the dot net framework? Ex. string s = "some...
1
by: Mark Jones | last post by:
Can anyone point me towards information/.net components that can be used for text extraction and pattern recognition? In particular, I am interested in working with a screenshot and extracting...
2
by: Kevin K | last post by:
Hi, I'm having a problem with extracting text from a Word document using StreamReader. As I'm developing a web application, I do NOT want the server to make calls to Word. I want to simply...
7
by: Tempo | last post by:
Hello. I am having a little trouble extracting text from a string. The string that I am dealing with is pasted below, and I want to extract the prices that are contained in the string below. Thanks...
8
by: dohyohdohyoh | last post by:
I have a programming question to generate an ordered list of alphanumeric strings of length 4. two alphabets rest numberst, etc. EG 0000-9999 then A000-Z999 then AA00 to ZZ99 then AAA0 - ZZZ9...
3
by: dohyohdohyoh | last post by:
I have a programming question to generate an ordered list of alphanumeric strings of length 4. two alphabets rest numberst, etc. EG 0000-9999 then A000-Z999 then AA00 to ZZ99 then AAA0 - ZZZ9...
2
by: franzdawg3 | last post by:
I find it hard to believe that there is not a native solution to this problem built into VB.NET but based on what I've come up with from MSDN and google if there is one it is not obvious. I have...
15
by: bitshift | last post by:
Anyone got an example ?
1
by: davidson1 | last post by:
Hai, i have a string 04AF045 in that AF are character , others are numbers , now what i need is i have to extract AF alone in ASP.NET written in vb. if anybody know pl reply me.. other...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.