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

RE: regex help

That’s it exactly..thx

-----Original Message-----
From: Reedick, Andrew [mailto:jr****@ATT.COM]
Sent: Tuesday, June 03, 2008 9:26 AM
To: Support Desk
Subject: RE: regex help

The regex will now skip anything with an '@'in the filename on the
assumption it's already in the correct format. Uncomment the os.rename line
once you're satisfied you won't mangle anything.
import glob
import os
import re
for filename in glob.glob('*.abook'):
newname = filename
newname = re.sub(r'^[^@]+\.abook$', '@domain.com.abook', filename)
if filename != newname:
print "rename", filename, "to", newname
#os.rename(filename, newname)
-----Original Message-----
From: Support Desk [mailto:mi**@ipglobal.net]
Sent: Tuesday, June 03, 2008 10:07 AM
To: Reedick, Andrew
Subject: RE: regex help

Thx for the reply,

I would first have to list all files matching user.abook then rename
them to
us**@domain.com.abook something like Im still new to python and haven't
had
much experience with the re module

import os
import re

emails = os.popen('ls').readlines()
for email in emails:
print email, '-->',
print re.findall(r'\.abook$', email)

-----Original Message-----
From: Reedick, Andrew [mailto:jr****@ATT.COM]
Sent: Tuesday, June 03, 2008 8:52 AM
To: Support Desk; py*********@python.org
Subject: RE: regex help
From: py********************************@python.org
[mailto:py********************************@python.o rg]
On Behalf Of Support Desk
Sent: Tuesday, June 03, 2008 9:32 AM
To: py*********@python.org
Subject: regex help

I am trying to put together a regular expression that will
rename users address books on our server due to a recent
change we made.* Users with address books user.abook need
to be changed to us**@domain.com.abook I'm having trouble
with the regex. Any help would be appreciated.

import re

emails = ('foo.abook', 'abook.foo', 'bob.abook.com', 'john.doe.abook')

for email in emails:
print email, '-->',
print re.sub(r'\.abook$', '@domain.com.abook', email)

*****

The information transmitted is intended only for the person or entity
to
which it is addressed and may contain confidential, proprietary, and/or
privileged material. Any review, retransmission, dissemination or other
use
of, or taking of any action in reliance upon this information by
persons or
entities other than the intended recipient is prohibited. If you
received
this in error, please contact the sender and delete the material from
all
computers. GA623

Jun 27 '08 #1
0 1597

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

Similar topics

6
by: Dave | last post by:
I'm struggling with something that should be fairly simple. I just don't know the regext syntax very well, unfortunately. I'd like to parse words out of what is basically a boolean search...
20
by: jeevankodali | last post by:
Hi I have an .Net application which processes thousands of Xml nodes each day and for each node I am using around 30-40 Regex matches to see if they satisfy some conditions are not. These Regex...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
7
by: Mike Labosh | last post by:
I have the following System.Text.RegularExpressions.Regex that is supposed to remove this predefined list of garbage characters from contact names that come in on import files : Dim...
9
by: jmchadha | last post by:
I have got the following html: "something in html ... etc.. city1... etc... <a class="font1" href="city1.html" onclick="etc."click for <b>info</bon city1 </a> ... some html. city1.. can repeat...
4
by: Chris | last post by:
Hi Everyone, I am using a regex to check for a string. When all the file contains is my test string the regex returns a match, but when I embed the test string in the middle of a text file a...
7
by: Extremest | last post by:
I am using this regex. static Regex paranthesis = new Regex("(\\d*/\\d*)", RegexOptions.IgnoreCase); it should find everything between parenthesis that have some numbers onyl then a forward...
6
by: Phil Barber | last post by:
I am using Regex to validate a file name. I have everything I need except I would like the dot(.) in the filename only to appear once. My question is it possible to allow one instance of character...
1
by: jonnyboy6969 | last post by:
Hi All Really hoping someone can help me out here with my deficient regex skills :) I have a function which takes a string of HTML and replaces a term (word or phrase) with a link. The pupose...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.