|
|||||
|
|
#1 |
|
|
The string consists of one to there parts, each parts is a underline followed by a number, and the number of the first part should be 0~31, and numbers of other parts should be larger than 31. The requested re should match the following strings: _3 _5_33 _21 _29_50 _29_700_700000 And the re shouldn't match the following strings: _3_5 the number of part 2 is less than 31 _43 the number of part 1 shouldn't be less than 31 _5_43_69_98 there shouldn't be more than 3 parts How to write the re, please? Thanks in advance. |
|
|
#2 |
|
|
exceptions; one of them is when the problem appears blatantly to be a homework. Perhaps if you showed that you worked on it and made some progress, but it's not quite right, someone may help you. George |
|
|
#3 |
|
|
Why do you look down upon homework? Everyone can do his homework well without any problems in your logic? It's a problem I met. I tried a lot and I can't work it out, so I came here for help. I saw someone complained that a question is too lengthy, and I saw some questions were complained to be unclear, but I never saw someone waste his time to judge if a question is a homework. If this is natural, I'll pay attention from now on. On 4 May 2005 01:31:48 -0700, George Sakkis <gsakkis@rutgers.edu> wrote: > This newsgroup is in general very helpful, but there are some > exceptions; one of them is when the problem appears blatantly to be a > homework. Perhaps if you showed that you worked on it and made some > progress, but it's not quite right, someone may help you. > > George > > -- > http://mail.python.org/mailman/listinfo/python-list > |
|
|
#4 |
|
|
On Wednesday 04 May 2005 11:34, could ildg wrote:
> Does it matter whether it is a homework? Yes, it does matter. We're not your CS-cl*** homework monkeys... :-) We're a forum of Python programmers who aid each other at thinking about solutions, we don't present solutions (normally), for a beautiful example of this, see the thread about finding similarities between two wave files... But, anyway, as an additional hint: the stuff you need to do _can_ be solved by an RE (the language you're matching is actually regular if you impose several restrictions), but I'd rather not do it that way. Programming a small function which splits the string and then does the appropriate checks (by using int) should be much easier and faster. And in case you really need an RE, watch this monster (to match a single term having numerical value >= 40)... 0*(([1-9][0-9]{2,})|([4-9][0-9])) Matching numbers >= 31 isn't hard too, I leave this as an exercise to the reader... :-) But beware, I'd guess this regex performs rather poorly with respect to backtracking on erraneous input such as "00000000000000000000000030"... --- Heiko. |
|
|
#5 |
|
|
Op 2005-05-04, could ildg schreef <could.net@gmail.com>:
> Does it matter whether it is a homework? Yes, because if other do your homework for you, you wont have learned anything from it. > Why do you look down upon homework? Who says he does. That he is not willing to do your homework for you, doesn't imply he looks down on it. > Everyone can do his homework well without any problems in your logic? There is difference in asking for help on how to solve a problem yourself and asking for the solution. -- Antoon Pardon |
|
|
#6 |
|
|
could ildg wrote:
> I need a regular expression to check if a string matches it. Why do you think you need a regular expression? If another approach that involved no regular expressions worked much better, would you reject it for some reason? -Peter |
|
|
#7 |
|
|
I can tell you that this is not any homework at all,
I think it by myself. I like this maillist, it helped me a lot. but some guys as you look weird. On 4 May 2005 10:25:20 GMT, Antoon Pardon <apardon@forel.vub.ac.be> wrote: > Op 2005-05-04, could ildg schreef <could.net@gmail.com>: > > Does it matter whether it is a homework? > > Yes, because if other do your homework for you, you wont > have learned anything from it. > > > Why do you look down upon homework? > > Who says he does. That he is not willing to do your homework > for you, doesn't imply he looks down on it. > > > Everyone can do his homework well without any problems in your logic? > > There is difference in asking for help on how to solve a > problem yourself and asking for the solution. I read the do***ent about re on python tommorow, and when I want to use it to settle a problem, I found it not so easy, so I raise the question here. I didn't say how I thought about it, because I don't want the question to be too long. But a short question doesn't mean that I am too lazy and I didn't even think about it. If you think I'm a kind of person you hate to help, you needn't. > > -- > Antoon Pardon > -- > http://mail.python.org/mailman/listinfo/python-list > |
|
|
#8 |
|
|
Thank you.
I just learned how to use re, so I want to find a way to settle it by using re. I know that split it into pieces will do it quickly. On 5/4/05, Peter Hansen <peter@engcorp.com> wrote: > could ildg wrote: > > I need a regular expression to check if a string matches it. > > Why do you think you need a regular expression? > > If another approach that involved no regular expressions worked much > better, would you reject it for some reason? > > -Peter > -- > http://mail.python.org/mailman/listinfo/python-list > |
|
|
#9 |
|
|
Personally I'd use groups.
|
|
|
#10 |
|
|
On Wednesday 04 May 2005 02:34 am, so sayeth could ildg:
> I saw someone complained that a question is too lengthy, > and I saw some questions were complained to be unclear, > but I never saw someone waste his time to judge if a question is a > homework. If this is natural, I'll pay attention from now on. > > On 4 May 2005 01:31:48 -0700, George Sakkis <gsakkis@rutgers.edu> wrote: > > This newsgroup is in general very helpful, but there are some > > exceptions; one of them is when the problem appears blatantly to be a > > homework. Perhaps if you showed that you worked on it and made some > > progress, but it's not quite right, someone may help you. I think by participating in this list, most of the members have felt that they have agreed to the following unofficial terms and conditions of use: http://www.catb.org/~esr/faqs/smart-questions.html The interesting thing is that those who follow the letter most strictly are usually the best ones to ask. Moreover, most members of this list are usually looking for any excuse to compose a regular expression. In fact, they probably come up with an answer before they make any ***essments about homework. > I can tell you that this is not any homework at all, > I think it by myself. In that case, your question is free game: >>> r = re.compile(r"_[0-3]\d?(_\d\d?){0,2}") >>> >>> r.search('_29_700_700000') <_sre.SRE_Match object at 0x402ccba0> >>> r.search('_29_50') <_sre.SRE_Match object at 0x402f8820> >>> r.search('_5_33') <_sre.SRE_Match object at 0x402ccba0> >>> r.search('_500') >>> James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ |