473,698 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I match this with re

Hello All
I have a problem here where I need to find the drive letters in a text
file and replace them with another letter. Now the lines can be as
long as this

6 'C:\pds\bddin64 \report\mto\' 'SJOSHI'
'D:\pds\bddin64 \report\format\ ' 'SJOSHI'

with multiple entries for path; i.e. there may be 2, as above or 1 or
more then 2. If I use the expression .*'([A-Z]:).*?', it only matches
the 2nd D: How do I get all the path groups ..??
thanks
Sunit
Jul 18 '05 #1
2 1583

"Sunit Joshi" <sj****@ingr.co m> wrote in message
news:8f******** *************** ***@posting.goo gle.com...
Hello All
I have a problem here where I need to find the drive letters in a text file and replace them with another letter. Now the lines can be as
long as this

6 'C:\pds\bddin64 \report\mto\' 'SJOSHI'
'D:\pds\bddin64 \report\format\ ' 'SJOSHI'

with multiple entries for path; i.e. there may be 2, as above or 1 or more then 2. If I use the expression .*'([A-Z]:).*?', it only matches the 2nd D: How do I get all the path groups ..??


Use file.readline() or .readlines() and then process one line at a
time.

Terry
Jul 18 '05 #2
On 4 Sep 2003 09:35:18 -0700, rumours say that sj****@ingr.com (Sunit
Joshi) might have written:
Hello All
I have a problem here where I need to find the drive letters in a text
file and replace them with another letter. Now the lines can be as
long as this

6 'C:\pds\bddin64 \report\mto\' 'SJOSHI'
'D:\pds\bddin6 4\report\format \' 'SJOSHI'

with multiple entries for path; i.e. there may be 2, as above or 1 or
more then 2. If I use the expression .*'([A-Z]:).*?', it only matches
the 2nd D: How do I get all the path groups ..??


I assume that the drive letters will be directly after a single quote.
You need this re:

reDriveLetter = re.compile(r"(? <=')[A-Z](?=:\\)").

You can try reDriveLetter.f indall() or the reDriveLetter.f inditer()
functions then, each match object will match a single capital letter.

Very important to everyone working with regular expressions: the
redemo.py script. Search for a Scripts directory in your python
directories (it's under Tools on Windows, otherwise get it from the
source distribution), redemo.py is in there along with other useful
scripts.
--
TZOTZIOY, I speak England very best,
Microsoft Security Alert: the Matrix began as open source.
Jul 18 '05 #3

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

Similar topics

1
1481
by: elmlish | last post by:
Hello all, I'm currently befuddled as to how to efficiently test for a positive re. match then use the results of that match in a function. Mostly what I've seen people do is to first test for the match, and then try matching again to get the results. This would seem to be pretty inefficient to me. I've tried making the match, then sending it to a variable, then testing
3
2530
by: bdwise | last post by:
I have this in my body tag: something();something(); document.thisForm.textBox1.focus();something(); And I want to find a part between the semicolons that ends in focus() and remove the entire value between the semicolons. My Regular Expression looks like this but it is not matching, can anyone help?
0
1935
by: Follower | last post by:
Hi, I am working on a function to return extracts from a text document with a specific phrase highlighted (i.e. display the context of the matched phrase). The requirements are: * Match should be case-insensitive, but extract should have case preserved.
6
2321
by: Matt Wette | last post by:
Over the last few years I have converted from Perl and Scheme to Python. There one task that I do often that is really slick in Perl but escapes me in Python. I read in a text line from a file and check it against several regular expressions and do something once I find a match. For example, in perl ... if ($line =~ /struct {/) { do something } elsif ($line =~ /typedef struct {/) { do something else
6
2305
by: Duane Morin | last post by:
I've inherited an XSL transform that I need to squeeze every last millisecond out of (since it's running several hundred thousand times). I've noticed that there are 26 match clauses in the file. They are 13 pairs that each check the same condition, like this: <xsl:template match="A/foo"> .... <xsl:template match="B/foo"> .... <xsl:template match="A/bar">
19
2152
by: Tom Deco | last post by:
Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. My (probably to naive) approach is: p = re.compile(r'\b#include\b) I also tried p = re.compile(r'\b\#include\b) in a futile attempt to use a backslash as escape character before the #
2
7945
by: Christian Staffe | last post by:
Hi, I would like to check for a partial match between an input string and a regular expression using the Regex class in .NET. By partial match, I mean that the input string could not yet be complete but I want to know if a match is possible so far. For instance I want to design a text box to enter a date and validate the correctness of the date as the user types character. If the user enters 1953/12/23 it will match my regex of course...
5
10180
by: JackRazz | last post by:
Anyone know the regular expression to match a blank line where the byte sequence is "0D 0A 0D 0A" ive tried "\r\n\r\n+", "^$+" "\n\r" with no success. Any Ideas? Thanks - JackRazz This is the code fragment I'm trying Dim r As Regex, m As Match, i As Integer
6
2719
by: EXI-Andrews, Jack | last post by:
the '*' and '+' don't seem to be greedy.. they will consume less in order to match a string: ('aa', 'ab') this is the sort of behaviour i'd expect from '(a+?)(ab)' a+ should greedily consume a's at the expense of the string not matching
4
7665
by: Dylan Nicholson | last post by:
I can write a regular expression that will only match strings that are NOT the word apple: ^(.*|a.*|ap.*|app.*|apple.+)$ But is there a neater way, and how would I do it to match strings that are NOT the word apple OR banana? Then what would be needed to match only strings that do not CONTAIN the word "apple" or "banana" or "cherry"?
0
8603
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,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7723
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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();...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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 we have to send another system
2
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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 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...

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.