473,503 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: replace numbers in a string

Beema Shafreen wrote:
hi All,

i have few lines in file
"ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaaga atgtgctttgattcg"
i need to replace the number and get only the alphabet in such a case
what should i do.
Can any body suggest me
From the regular expression module, use re.sub like this:
>>import re
re.sub('[0-9]', '',
"ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaaga atgtgctttgattcg")
'ttccatttctggacatgacgtctgtggtttaagctttgtgaaagaatgt gctttgattcg'
Gary Herron
>
--
Beema Shafreen
------------------------------------------------------------------------

--
http://mail.python.org/mailman/listinfo/python-list
Oct 9 '08 #1
1 2196
Gary Herron wrote:
Beema Shafreen wrote:
>hi All,

i have few lines in file
"ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaag aatgtgctttgattcg"
i need to replace the number and get only the alphabet in such a case
what should i do.
Can any body suggest me
From the regular expression module, use re.sub like this:

>>>import re
re.sub('[0-9]', '',
"ttccatttctggacatgacgtctgt6901ggtttaagctttgtgaaaga atgtgctttgattcg")
'ttccatttctggacatgacgtctgtggtttaagctttgtgaaagaatgt gctttgattcg'
Or use str methods.
In Python 2.6:
>>import string
"tctgt6901ggtttaa".translate(None, string.digits)
'tctgtggtttaa'

Older versione:
>>"tctgt6901ggtttaa".translate(string.maketrans("" , ""), string.digits)
'tctgtggtttaa'

Peter
Oct 9 '08 #2

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

Similar topics

14
15976
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
19
2906
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
4
62084
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
6
2402
by: Markus Rosenstihl | last post by:
Hi, I wonder if i can make this nicer: In my case a list is created from a bill which is a tab seperated file and each line looks like this: "Verbindungen Deutsche Telekom vom 03.08.2005 bis...
16
9043
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: ...
18
4582
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
8
1543
by: Aussie Rules | last post by:
Hi, I have a string that is built on the fly, and often of different lengths. The string contains a series of numbers with a comma seperating each number. For example ...
4
1906
by: ds4ff1z | last post by:
Hello, i'm looking to find and replace multiple characters in a text file (test1). I have a bunch of random numbers and i want to replace each number with a letter (such as replace a 7 with an f ...
9
1339
by: Jake Barnes | last post by:
I need to change imageUploadInfo2 to caption2 where the number at the end is a variable that needs to be preserved (imageUploadInfo1 to caption1, imageUploadInfo43 to caption43, etc) Can anyone...
3
2927
by: mark | last post by:
I have a table of UK companies whose records I want to filter using a map of postcode regions. For the benfit of people outside the UK, our postcodes are a pain to work with because they are not...
0
7188
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
7063
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...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7313
jinu1996
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...
0
4663
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...
0
3156
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...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
366
bsmnconsultancy
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...

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.