Re: [Tutor] regexp

2011-11-07 Thread Peter Otten
Albert-Jan Roskam wrote: > Nice solution indeed! Will it also work with accented characters? And how > should one incorporate the collating sequence into the solution? By > explicitly setting the locale? It might be nice if the outcome is always > the same, whereever you are in the world. This is

Re: [Tutor] regexp

2011-11-07 Thread Albert-Jan Roskam
? ~~ > >From: Terry Carroll >To: tutor@python.org >Sent: Sunday, November 6, 2011 8:21 PM >Subject: Re: [Tutor] regexp > >On Sat, 5 Nov 2011, Dinara Vakhitova wrote: > >> I need to find the words in a corpus, which l

Re: [Tutor] regexp

2011-11-07 Thread Peter Otten
Asokan Pichai wrote: > IMO the regex is not too bad; I will not use it for this job -- typing > a 50+ character string > is more painful (and more error prone) than writing 5--10 lines of code. Well, you can build the string programmatically: >>> "*".join(string.ascii_lowercase) + "*" 'a*b*c*d*e

Re: [Tutor] regexp

2011-11-06 Thread Asokan Pichai
IMO the regex is not too bad; I will not use it for this job -- typing a 50+ character string is more painful (and more error prone) than writing 5--10 lines of code. That said, if it made you look at regexes deeply and beyond the simple explanation of what each character (*, ., +) does I think th

Re: [Tutor] regexp

2011-11-06 Thread Dinara Vakhitova
Dear Terry, Thank you for your advise, I'll try to implement it. D. 2011/11/6 Terry Carroll > On Sat, 5 Nov 2011, Dinara Vakhitova wrote: > > I need to find the words in a corpus, which letters are in the >> alphabetical >> order ("almost", "my" etc.) >> I started with matching two consecutiv

Re: [Tutor] regexp

2011-11-06 Thread Terry Carroll
On Sat, 5 Nov 2011, Dinara Vakhitova wrote: I need to find the words in a corpus, which letters are in the alphabetical order ("almost", "my" etc.) I started with matching two consecutive letters in a word, which are in the alphabetical order, and tried to use this expression: ([a-z])[\1-z], but

Re: [Tutor] regexp

2011-11-05 Thread Dinara Vakhitova
Oh, sorry, of course it should be without brackets: 'a*b*c*...' > [a*b*c*d*...x*y*z*] 2011/11/5 Dinara Vakhitova > Steven, Walter, Dave, Peter and Albert, > > First of all, thank you very much for your suggestions, I appreciate a lot > your help. I would only like to mention that I would have

Re: [Tutor] regexp

2011-11-05 Thread Dinara Vakhitova
Steven, Walter, Dave, Peter and Albert, First of all, thank you very much for your suggestions, I appreciate a lot your help. I would only like to mention that I would have never asked something to be done for me just because it's my homework, I posted this question only because I couldn't find a

Re: [Tutor] regexp

2011-11-05 Thread Albert-Jan Roskam
___ >From: Dave Angel >To: Steven D'Aprano >Cc: tutor@python.org >Sent: Saturday, November 5, 2011 2:49 AM >Subject: Re: [Tutor] regexp > >On 11/04/2011 07:00 PM, Steven D'Aprano wrote: >> Dinara Vakhitova wrote: >>> Hello, >>> >

Re: [Tutor] regexp

2011-11-05 Thread Peter Otten
Steven D'Aprano wrote: > Good luck with the question! If you do solve it, please come back and > tell us how you did it. I for one am curious now whether or not it can > be done using Python regexes. Perhaps someone else might have a > solution. You could try the python-l...@python.org mailing lis

Re: [Tutor] regexp

2011-11-04 Thread Dave Angel
On 11/04/2011 07:00 PM, Steven D'Aprano wrote: Dinara Vakhitova wrote: Hello, I need to find the words in a corpus, which letters are in the alphabetical order ("almost", "my" etc.) Quoting Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular

Re: [Tutor] regexp

2011-11-04 Thread Walter Prins
Dinara, Steven, On 4 November 2011 23:29, Steven D'Aprano wrote: > Is this homework? You should have said so. > Inded he should've... > I don't understand questions like this. Do carpenters ask their > apprentices to cut a piece of wood with a hammer? Do apprentice chefs get > told to dice ca

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Sorry, I didn´t know that I couldn´t ask questions about the homework... You're welcome to ask questions about homework or school projects, but most of the people here believe that ethically the student should do the homework, not the tutor :) So if something looks

Re: [Tutor] regexp

2011-11-04 Thread Sander Sweers
On 5 November 2011 00:38, Dinara Vakhitova wrote: > Sorry, I didn´t know that I couldn´t ask questions about the homework... This list is meant to help with learning python and not to do homework assignments. So if you get stuck with something yes you can post it but be open about it and show wh

Re: [Tutor] regexp

2011-11-04 Thread Dinara Vakhitova
Sorry, I didn´t know that I couldn´t ask questions about the homework... I wanted to do it recursively, like this: def check_abc(string): string = string.lower() check_pair = re.compile("([a-z])[\1-z]") if check_pair.match(string): if check_abc(string[1:]): return T

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Thank you for your answer, Steven. Of course it would have been easier to write this function, but unfortunately my task is to do it with a regular expression :( Is this homework? You should have said so. I don't understand questions like this. Do carpenters ask their

Re: [Tutor] regexp

2011-11-04 Thread Dinara Vakhitova
Thank you for your answer, Steven. Of course it would have been easier to write this function, but unfortunately my task is to do it with a regular expression :( D. 2011/11/5 Steven D'Aprano > Dinara Vakhitova wrote: > >> Hello, >> >> I need to find the words in a corpus, which letters are in

Re: [Tutor] regexp

2011-11-04 Thread Steven D'Aprano
Dinara Vakhitova wrote: Hello, I need to find the words in a corpus, which letters are in the alphabetical order ("almost", "my" etc.) Quoting Jamie Zawinski: Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Now yo

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Alex Hall
On 10/1/10, Steven D'Aprano wrote: > On Sat, 2 Oct 2010 01:14:27 am Alex Hall wrote: >> >> Here is my test: >> >> s=re.search(r"[\d+\s+\d+\s+\d]", l) >> > >> > Try this instead: >> > >> > re.search(r'\d+\s+\D*\d+\s+\d', l) > [...] >> Understood. My intent was to ask why my regexp would match anyth

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Steven D'Aprano
On Sat, 2 Oct 2010 01:14:27 am Alex Hall wrote: > >> Here is my test: > >> s=re.search(r"[\d+\s+\d+\s+\d]", l) > > > > Try this instead: > > > > re.search(r'\d+\s+\D*\d+\s+\d', l) [...] > Understood. My intent was to ask why my regexp would match anything > at all. Square brackets create a charact

Re: [Tutor] regexp: a bit lost

2010-10-01 Thread Alex Hall
On 10/1/10, Steven D'Aprano wrote: > On Fri, 1 Oct 2010 12:45:38 pm Alex Hall wrote: >> Hi, once again... >> I have a regexp that I am trying to use to make sure a line matches >> the format: [c*]n [c*]n n >> where c* is (optionally) 0 or more non-numeric characters and n is >> any numeric charact

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Gerard Flanagan
with coffee: yes = """ v1 v2 5 2 someword7 3 """.splitlines()[1:] no = """ word 2 3 1 2 """.splitlines()[1:] import re pattern = "(\w*\d\s+?)(\w*\d\s+?)(\d)$" rx = re.compile(pattern) for line in yes: m = rx.match(line) assert m print([part.rstrip() for part in m.groups()]) f

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Steven D'Aprano
On Fri, 1 Oct 2010 12:45:38 pm Alex Hall wrote: > Hi, once again... > I have a regexp that I am trying to use to make sure a line matches > the format: [c*]n [c*]n n > where c* is (optionally) 0 or more non-numeric characters and n is > any numeric character. The spacing should not matter. These sh

Re: [Tutor] regexp: a bit lost

2010-09-30 Thread Gerard Flanagan
Alex Hall wrote: Hi, once again... I have a regexp that I am trying to use to make sure a line matches the format: [c*]n [c*]n n where c* is (optionally) 0 or more non-numeric characters and n is any numeric character. The spacing should not matter. These should pass: v1 v2 5 2 someword7 3 whi

Re: [Tutor] regexp help needed

2006-10-18 Thread János Juhász
Hi Kent, thanks your respond. > > I have to remove the thousand separator by moving the numbers before it to > > right. > > So the number and char groups has to be left in their original position. > > > > I have to make this kind of changes on the problematic lines: > > MOATOT79 47.2

Re: [Tutor] regexp help needed

2006-10-18 Thread Kent Johnson
János Juhász wrote: > Dear All, > > I have a problem about the EDI invoices created by our erp system. > I have to make a small correction on them, just before sending them by > ftp. > > The problem is that, the big numbers are printed with thousand separator. > > U:\ediout\INVOIC\Backup>grep \

Re: [Tutor] Regexp with multiple patterns in Python

2005-08-16 Thread Kent Johnson
Kristian Evensen wrote: > What I want to do is to check for two patterns to make sure all > occurrences of pattern1 and pattern2 come in the same order as they do > in the file I parse. It it contains a number of computer-games I would > like the output to look something like this: > > PC, Batt

RE: [Tutor] Regexp Not Matching on Numbers?

2004-12-14 Thread Danny Yoo
On Tue, 14 Dec 2004, Gooch, John wrote: > I am used to ( in Perl ) the entire string being searched for a match > when using RegExp's. I assumed this was the way Python would do it do, > as Java/Javascript/VbScript all behaved in this manner. However, I found > that I had to add ".*" in front of

RE: [Tutor] Regexp Not Matching on Numbers?

2004-12-14 Thread Gooch, John
To: Gooch, John Cc: '[EMAIL PROTECTED]' Subject: Re: [Tutor] Regexp Not Matching on Numbers? I'm not too sure what you are trying to do here, but the re in your code matches the names in your example data: >>> import re >>> name = 'partners80_access_lo

Re: [Tutor] Regexp Not Matching on Numbers?

2004-12-14 Thread Kent Johnson
Max Noel wrote: On Dec 14, 2004, at 18:15, Gooch, John wrote: So far I have tried the following regular expressions: "\d+" "\d*" "\W+" "\W*" "[1-9]+" and more... I think you have to escape the backslashes. or use raw strings like r"\d+" which is what is in the sample code... Kent _

Re: [Tutor] Regexp Not Matching on Numbers?

2004-12-14 Thread Kent Johnson
I'm not too sure what you are trying to do here, but the re in your code matches the names in your example data: >>> import re >>> name = 'partners80_access_log.1102723200' >>> re.compile(r"([\w]+)").match( name ).groups() ('partners80_access_log',) One thing that may be tripping you up is that r

Re: [Tutor] Regexp Not Matching on Numbers?

2004-12-14 Thread Max Noel
On Dec 14, 2004, at 18:15, Gooch, John wrote: This is weird. I have a script that checks walks through directories, checks to see if their name matches a certain format ( regular expression ), and then prints out what it finds. However, it refuses to ever match on numbers unless the regexp is ".