Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Frank Bloeink
Hi [Christian|List]

This post is not regarding your special problem (which anyway has been
solved by now), but I'd like to share some general tip on working with
regular expressions.
There are some nice regex-debuggers out there that can help clearify
what went wrong when a regex doesn't match when it should or vice versa.

Kodos http://kodos.sourceforge.net/ is one of them, but there are many
others that can make your life easier ; at least in terms of
regex-debugging ;) 

Probably most of you (especially all regex-gurus) know about this
already, but i thought it was worth the post as a hint for all beginners

hth Frank

On Wed, 2005-10-19 at 09:45 +0200, Christian Meesters wrote:
 Hi
 
 I've got the problem that I need to find a certain group of file names 
 within a lot of different file names. Those I want to match with a 
 regular expression are a bit peculiar since they all look like:
 ...
 ...(regex-problem)
 ...
 Any ideas what I could do else?
 TIA
 Christian
 
 PS Hope that I described the problem well enough ...



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-20 Thread Hugo González Monteverde
I personally fancy Kiki, that comes with the WxPython installer... It 
has very nice coloring for grouping in Regexes.

Hugo

Kent Johnson wrote:
 Frank Bloeink wrote:
 
There are some nice regex-debuggers out there that can help clearify
what went wrong when a regex doesn't match when it should or vice versa.

Kodos http://kodos.sourceforge.net/ is one of them, but there are many
others that can make your life easier ; at least in terms of
regex-debugging ;) 
 
 
 Yes, these programs can be very helpful. There is even one that ships with 
 Python - see
 C:\Python24\Tools\Scripts\redemo.py
 
 Kent
 
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Hi

I've got the problem that I need to find a certain group of file names 
within a lot of different file names. Those I want to match with a 
regular expression are a bit peculiar since they all look like:
07SS.INF , 10SE.INF, 13SS.INF, 02BS.INF, 05SS.INF.
Unfortunately there are similar file names that shouldn't be matched, 
like:
01BE.INF, 02BS.INF
Any other extension than 'INF' should also be skipped. (There are names 
like 07SS.E00, wich I don't want to see matched.)
So I tried the following pattern (using re):
\d+[SS|SE]\.INF - as there should be at least one digit, the group 'SE' 
or 'SS' followed by a dot and the extension 'INF'.

Well, this doesn't work, no match. However, if I change the pattern to 
\d+[SS|SE] it somehow works and all all valid names are matched. But if 
there is a different extension than 'INF' it matches too - but it 
shouldn't. (Surrounding the dot with [] doesn't help, though I have no 
idea as for why.)
Any ideas what I could do else?

TIA
Christian

PS Hope that I described the problem well enough ...

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Kent Johnson
Christian Meesters wrote:
 Hi
 
 I've got the problem that I need to find a certain group of file names 
 within a lot of different file names. Those I want to match with a 
 regular expression are a bit peculiar since they all look like:
 07SS.INF , 10SE.INF, 13SS.INF, 02BS.INF, 05SS.INF.
 Unfortunately there are similar file names that shouldn't be matched, 
 like:
 01BE.INF, 02BS.INF
 Any other extension than 'INF' should also be skipped. (There are names 
 like 07SS.E00, wich I don't want to see matched.)
 So I tried the following pattern (using re):
 \d+[SS|SE]\.INF - as there should be at least one digit, the group 'SE' 
 or 'SS' followed by a dot and the extension 'INF'.

Use parentheses () for grouping. Brackets [] define a group of characters. Your 
re says to match
  \d+ one or more digits
  [SS|SE] exactly one of the characters S, |, E
  \.INF literal .INF

Since there are TWO characters S or E, nothing matches. Change the [] to () and 
it works.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Misto .
[ Workaround ]
What about using the glob module?

http://docs.python.org/lib/module-glob.html

you can use something like
glob.glob('./[0-9][0-9]S[E|S].INF')
(Not tested)


Misto
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Actually, your answer did help to open my eyes. The expression is 
\d+S[S|E]\.INF: Ouch!

Thanks a lot,
Christian

On 19 Oct 2005, at 12:11, Misto . wrote:

 [ Workaround ]
 What about using the glob module?

 http://docs.python.org/lib/module-glob.html

 you can use something like
 glob.glob('./[0-9][0-9]S[E|S].INF')
 (Not tested)


 Misto


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Kent Johnson
Christian Meesters wrote:
 Actually, your answer did help to open my eyes. The expression is 
 \d+S[S|E]\.INF: Ouch!

That will work, but what you really mean is one of these:
\d+S[SE]\.INF
\d+S(S|E)\.INF

Your regex will match 0S|.INF

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] regular expression matching a dot?

2005-10-19 Thread Christian Meesters
Thanks, corrected. I was happy now - and then too fast ;-).

Cheers
Christian
On 19 Oct 2005, at 13:50, Kent Johnson wrote:

 Christian Meesters wrote:
 Actually, your answer did help to open my eyes. The expression is 
 \d+S[S|E]\.INF: Ouch!

 That will work, but what you really mean is one of these:
 \d+S[SE]\.INF
 \d+S(S|E)\.INF

 Your regex will match 0S|.INF

 Kent


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor