Re: grimace: a fluent regular expression generator in Python

2013-07-17 Thread Johann Hibschman
Ben Last b...@benlast.com writes: Good points. I wanted to find a syntax that allows comments as well as being fluent: RE() .any_number_of.digits # Recall that any_number_of includes zero .followed_by.an_optional.dot.then.at_least_one.digit # The dot is specifically optional # but we must

Re: grimace: a fluent regular expression generator in Python

2013-07-17 Thread Roy Smith
In article mailman.4772.1373978931.3114.python-l...@python.org, Anders J. Munch 2...@jmunch.dk wrote: The problem with Perl-style regexp notation isn't so much that it's terse - it's that the syntax is irregular (sic) and doesn't follow modern principles for lexical structure in computer

Re: grimace: a fluent regular expression generator in Python

2013-07-17 Thread Gregory Ewing
Ben Last wrote: north_american_number_re = (RE().start .literal('(').followed_by.__exactly(3).digits.then.__literal(')') .then.one.literal(-).then.__exactly(3).digits .then.one.dash.followed_by.__exactly(4).digits.then.end

grimace: a fluent regular expression generator in Python

2013-07-16 Thread Ben Last
Hi all I'd be interested in comments on a fluent regular expression generator I've been playing with (inspired by the frustrations of a friend of mine who's learning). The general use case is to be able to construct RE strings such as: r'^\(\d{3,3}\)-{1,1}\d{3,3}\-{1,1}\d{4,4}$' (intended

help on python regular expression named group

2013-07-16 Thread Mohan L
Dear All, Here is my script : #!/usr/bin/python import re # A string. logs = date=2012-11-28 time=21:14:59 # Match with named groups. m = re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))), logs) # print print m.groupdict() Output: {'date': '2012-11-28', 'datetime':

Re: grimace: a fluent regular expression generator in Python

2013-07-16 Thread Joshua Landau
On 15 July 2013 23:21, Ben Last benl...@gmail.com wrote: Hi all I'd be interested in comments on a fluent regular expression generator I've been playing with (inspired by the frustrations of a friend of mine who's learning). The general use case is to be able to construct RE strings

Re: help on python regular expression named group

2013-07-16 Thread Joshua Landau
On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com wrote: Dear All, Here is my script : #!/usr/bin/python import re # A string. logs = date=2012-11-28 time=21:14:59 # Match with named groups. m = re.match((?Pdatetime(date=(?Pdate[^\s]+))\s+(time=(?Ptime[^\s]+))), logs) # print

Re: help on python regular expression named group

2013-07-16 Thread Mohan L
On Tue, Jul 16, 2013 at 2:12 PM, Joshua Landau jos...@landau.ws wrote: On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com wrote: Dear All, Here is my script : #!/usr/bin/python import re # A string. logs = date=2012-11-28 time=21:14:59 # Match with named groups. m =

Re: grimace: a fluent regular expression generator in Python

2013-07-16 Thread Anders J. Munch
Ben Last wrote: north_american_number_re = (RE().start .literal('(').followed_by.exactly(3).digits.then.literal(')') .then.one.literal(-).then.exactly(3).digits .then.one.dash.followed_by.exactly(4).digits.then.end

Re: help on python regular expression named group

2013-07-16 Thread MRAB
On 16/07/2013 11:18, Mohan L wrote: On Tue, Jul 16, 2013 at 2:12 PM, Joshua Landau jos...@landau.ws mailto:jos...@landau.ws wrote: On 16 July 2013 07:55, Mohan L l.mohan...@gmail.com mailto:l.mohan...@gmail.com wrote: Dear All, Here is my script :

Re: help on python regular expression named group

2013-07-16 Thread Joshua Landau
On 16 July 2013 16:38, MRAB pyt...@mrabarnett.plus.com wrote: On 16/07/2013 11:18, Mohan L wrote: I using another third party python script. It takes the regex from configuration file. I can't write any code. I have to do all this in single regex. A capture group captures a single

Re: Regular expression negative look-ahead

2013-07-03 Thread Jason Friedman
Huh, did not realize that endswith takes a list. I'll remember that in the future. This need is actually for http://schemaspy.sourceforge.net/, which allows one to include only tables/views that match a pattern. Either there is a bug in Schemaspy's code or Java's implementation of regular

Re: Regular expression negative look-ahead

2013-07-03 Thread Jason Friedman
why. On Mon, Jul 1, 2013 at 5:07 PM, Jason Friedman jsf80...@gmail.com wrote: I have table names in this form: MY_TABLE MY_TABLE_CTL MY_TABLE_DEL MY_TABLE_RUN YOUR_TABLE YOUR_TABLE_CTL YOUR_TABLE_DEL YOUR_TABLE_RUN I am trying to create a regular expression

Regular expression negative look-ahead

2013-07-02 Thread Jason Friedman
I have table names in this form: MY_TABLE MY_TABLE_CTL MY_TABLE_DEL MY_TABLE_RUN YOUR_TABLE YOUR_TABLE_CTL YOUR_TABLE_DEL YOUR_TABLE_RUN I am trying to create a regular expression that will return true for only these tables: MY_TABLE YOUR_TABLE I tried these: pattern = re.compile(r_(?!(CTL|DEL

Re: Regular expression negative look-ahead

2013-07-02 Thread Neil Cerutti
On 2013-07-01, Jason Friedman jsf80...@gmail.com wrote: I have table names in this form: MY_TABLE MY_TABLE_CTL MY_TABLE_DEL MY_TABLE_RUN YOUR_TABLE YOUR_TABLE_CTL YOUR_TABLE_DEL YOUR_TABLE_RUN I am trying to create a regular expression that will return true for only these tables

Re: Regular expression negative look-ahead

2013-07-01 Thread Jason Friedman
names in this form: MY_TABLE MY_TABLE_CTL MY_TABLE_DEL MY_TABLE_RUN YOUR_TABLE YOUR_TABLE_CTL YOUR_TABLE_DEL YOUR_TABLE_RUN I am trying to create a regular expression that will return true for only these tables: MY_TABLE YOUR_TABLE I tried these: pattern = re.compile(r_(?!(CTL|DEL|RUN

Re: Regular expression negative look-ahead

2013-07-01 Thread Ian Kelly
1, 2013 at 5:07 PM, Jason Friedman jsf80...@gmail.com wrote: I have table names in this form: MY_TABLE MY_TABLE_CTL MY_TABLE_DEL MY_TABLE_RUN YOUR_TABLE YOUR_TABLE_CTL YOUR_TABLE_DEL YOUR_TABLE_RUN I am trying to create a regular expression that will return true for only these tables

Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
word and last word are varying. I am looking to extract out: (i) the (ii) the (iii) the (iv) this (v) this (vi) the new . The problem may be handled by converting the string to list and then index of list. But I am thinking if I can use regular expression in Python. If any

Re: Pattern Search Regular Expression

2013-06-15 Thread Steven D'Aprano
and then index of list. No need for a regular expression. py sentence = By the new group py words = sentence.split() py words[1:-1] ['the', 'new'] Does that help? -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
. But I am thinking if I can use regular expression in Python. If any one of the esteemed members can help. Thanking you in Advance, Regards, Subhabrata I tend to reach for string methods rather than an RE so will something like this suit you? c:\Users\Mark\MyPythontype a.py for s

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
by converting the string to list and then index of list. No need for a regular expression. py sentence = By the new group py words = sentence.split() py words[1:-1] ['the', 'new'] Does that help? I thought OP wanted: words[words[0],words[-1]] But that might be just my caffeine deprived

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
. The problem may be handled by converting the string to list and then index of list. No need for a regular expression. py sentence = By the new group py words = sentence.split() py words[1:-1] ['the', 'new'] Does that help? I thought OP wanted: words[words[0],words[-1]] But that might be just

Re: Pattern Search Regular Expression

2013-06-15 Thread rusi
to extract out:    (i) the (ii) the (iii) the (iv) this (v) this (vi) the new        . The problem may be handled by converting the string to list and then index of list. No need for a regular expression. py sentence = By the new group py words = sentence.split() py words[1:-1

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 11:55:34 +0100, Mark Lawrence wrote: sentence = By the new group words = sentence.split() words[words[0],words[-1]] Traceback (most recent call last): File stdin, line 1, in module TypeError: list indices must be integers, not tuple So why would the OP want

Re: Pattern Search Regular Expression

2013-06-15 Thread Denis McMahon
On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote: first_and_last = [sentence.split()[i] for i in (0, -1)] middle = sentence.split()[1:-2] Bugger! That last is actually: sentence.split()[1:-1] It just looks like a two. -- Denis McMahon, denismfmcma...@gmail.com --

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 14:45, Denis McMahon wrote: On Sat, 15 Jun 2013 13:41:21 +, Denis McMahon wrote: first_and_last = [sentence.split()[i] for i in (0, -1)] middle = sentence.split()[1:-2] Bugger! That last is actually: sentence.split()[1:-1] It just looks like a two. I've a very strong

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
are the mighty fallen. -- Steve is going for the pink ball - and for those of you who are watching in black and white, the pink is next to the green. Snooker commentator 'Whispering' Ted Lowe. Mark Lawrence Dear Group, I know this solution but I want to have Regular Expression

Re: Pattern Search Regular Expression

2013-06-15 Thread Andreas Perstinger
subhabangal...@gmail.com wrote: I know this solution but I want to have Regular Expression option. Just learning. http://mattgemmell.com/2008/12/08/what-have-you-tried/ Just spell out what you want: A word at the beginning, followed by any text, followed by a word at the end. Now look up

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 15:31, subhabangal...@gmail.com wrote: Dear Group, I know this solution but I want to have Regular Expression option. Just learning. Regards, Subhabrata. Start here http://docs.python.org/2/library/re.html Would you also please read and action this, http://wiki.python.org

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Saturday, June 15, 2013 8:34:59 PM UTC+5:30, Mark Lawrence wrote: On 15/06/2013 15:31, subhabangal...@gmail.com wrote: Dear Group, I know this solution but I want to have Regular Expression option. Just learning. Regards, Subhabrata. Start here http

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 17:28, subhabangal...@gmail.com wrote: You've been pointed at several links, so what have you tried, and what, if anything, went wrong? Or do you simply not understand, in which case please say so and we'll help. I'm not trying to be awkward, it's simply known that you learn

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
and then index of list. But I am thinking if I can use regular expression in Python. Since nobody here seems to want to answer your question (or seems even able to read it), I'll try. Is something like this what you want? import re texts = [ '(i)In the ocean', '(ii)On the ocean', '(iii

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
. The problem may be handled by converting the string to list and then index of list. But I am thinking if I can use regular expression in Python. If any one of the esteemed members can help. Thanking you in Advance, Regards, Subhabrata Dear Group, Thank you

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
On Saturday, June 15, 2013 11:54:28 AM UTC-6, subhaba...@gmail.com wrote: Thank you for the answer. But I want to learn bit of interesting regular expression forms where may I? No Mark, thank you for your links but they were not sufficient. Links to the Python reference documentation

Re: Pattern Search Regular Expression

2013-06-15 Thread subhabangalore
On Sunday, June 16, 2013 12:17:18 AM UTC+5:30, ru...@yahoo.com wrote: On Saturday, June 15, 2013 11:54:28 AM UTC-6, subhaba...@gmail.com wrote: Thank you for the answer. But I want to learn bit of interesting regular expression forms where may I? No Mark, thank you for your links

Re: Pattern Search Regular Expression

2013-06-15 Thread Terry Reedy
On 6/15/2013 12:28 PM, subhabangal...@gmail.com wrote: Suppose I want a regular expression that matches both Sent from my iPhone and Sent from my iPod. How do I write such an expression--is the problem, Sent from my iPod Sent from my iPhone which can be written as, re.compile(Sent from my

Re: Pattern Search Regular Expression

2013-06-15 Thread rurpy
Oops... On Saturday, June 15, 2013 12:47:18 PM UTC-6, ru...@yahoo.com wrote: Links to the Python reference documentation are useful for people just beginning with some aspect of Python; they are for people who already know Python and want to look up details. That was supposed to be: Links

Re: Pattern Search Regular Expression

2013-06-15 Thread Joshua Landau
On 15 June 2013 11:18, Mark Lawrence breamore...@yahoo.co.uk wrote: I tend to reach for string methods rather than an RE so will something like this suit you? c:\Users\Mark\MyPythontype a.py for s in (In the ocean, On the ocean, By the ocean, In this group,

Re: Pattern Search Regular Expression

2013-06-15 Thread Mark Lawrence
On 15/06/2013 22:03, Joshua Landau wrote: On 15 June 2013 11:18, Mark Lawrence breamore...@yahoo.co.uk wrote: I tend to reach for string methods rather than an RE so will something like this suit you? c:\Users\Mark\MyPythontype a.py for s in (In the ocean, On the ocean,

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-14 Thread Kevin LaTona
On Jun 13, 2013, at 7:42 AM, Kevin LaTona li...@studiosola.com wrote: With the following code tweaks in Python 2.7.2, I find it works with VERBOSE for me, but not without. Sorry had a small bleep while writing that last line this AM. Of course the regex pattern would work in VERBOSE mode as

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-14 Thread rice . stew
On Thursday, June 13, 2013 3:17:28 AM UTC-4, Andreas Perstinger wrote: On 13.06.2013 02:59, rice.cr...@gmail.com wrote: I am parsing the output of an open-iscsi command that contains severalblocks of data for each data set. Each block has the format: [SNIP] for your example (same

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-14 Thread rice . stew
On Thursday, June 13, 2013 5:07:33 PM UTC-4, Kevin LaTona wrote: On Jun 13, 2013, at 7:42 AM, Kevin LaTona li...@studiosola.com wrote: With the following code tweaks in Python 2.7.2, I find it works with VERBOSE for me, but not without. Sorry had a small bleep while writing that

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-13 Thread Andreas Perstinger
On 13.06.2013 02:59, rice.cr...@gmail.com wrote: I am parsing the output of an open-iscsi command that contains severalblocks of data for each data set. Each block has the format: [SNIP] I tried using \s* to swallow the whitespace between the to iSCSI lines. No joy... However [\s\S]*? allows

Re: Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-13 Thread Kevin LaTona
On Jun 12, 2013, at 5:59 PM, rice.cr...@gmail.com wrote: I am parsing the output of an open-iscsi command that contains several blocks of data for each data set. Each block has the format: Lastly, a version of this regex as a non-VERBOSE expression works as expected.. Something about

Problem creating a regular expression to parse open-iscsi, iscsiadm output (help?)

2013-06-12 Thread rice . cruft
I am parsing the output of an open-iscsi command that contains several blocks of data for each data set. Each block has the format: Target: iqn.1992-04.com.emc:vplex-8460319f-0007 Current Portal: 221.128.52.224:3260,7 Persistent Portal: 221.128.52.224:3260,7

[issue17998] internal error in regular expression engine

2013-06-02 Thread Matthias Klose
Matthias Klose added the comment: what's the status on this one? Can the proposed patch be applied until the decision whether to backout the original change, or not? -- nosy: +doko, georg.brandl, larry priority: normal - release blocker ___ Python

[issue17998] internal error in regular expression engine

2013-06-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I'm working on tests. No need to rush. -- stage: patch review - test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___

[issue17998] internal error in regular expression engine

2013-05-18 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___

[issue17998] internal error in regular expression engine

2013-05-18 Thread Antoine Pitrou
Antoine Pitrou added the comment: Perhaps it would be safer to revert the original commit in bugfix branches, and just commit the better patch in default? -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998

[issue17998] internal error in regular expression engine

2013-05-17 Thread Jeroen Demeyer
for more information. import re re.compile('(.*)\.[0-9]*\.[0-9]*$', re.I|re.S).findall('3.0.0') Traceback (most recent call last): File stdin, line 1, in module RuntimeError: internal error in regular expression engine This is a 2.7.5 regression, 2.7.4 worked fine. -- components

[issue17998] internal error in regular expression engine

2013-05-17 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- components: +Regular Expressions nosy: +benjamin.peterson, ezio.melotti, mrabarnett type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998

[issue17998] internal error in regular expression engine

2013-05-17 Thread Benjamin Peterson
Benjamin Peterson added the comment: 27162465316f -- assignee: - serhiy.storchaka nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___

[issue17998] internal error in regular expression engine

2013-05-17 Thread Christian Heimes
Changes by Christian Heimes li...@cheimes.de: -- nosy: +christian.heimes ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___ ___

[issue17998] internal error in regular expression engine

2013-05-17 Thread Benjamin Peterson
Benjamin Peterson added the comment: Also, note this particular case only reproduces on 32 bit. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___

[issue17998] internal error in regular expression engine

2013-05-17 Thread Christian Heimes
(most recent call last): File string, line 1, in module RuntimeError: internal error in regular expression engine -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998

[issue17998] internal error in regular expression engine

2013-05-17 Thread Matthew Barnett
Matthew Barnett added the comment: Here are some simpler examples of the bug: re.compile('.*yz', re.S).findall('xyz') re.compile('.?yz', re.S).findall('xyz') re.compile('.+yz', re.S).findall('xyz') Unfortunately I find it difficult to see what's happening when single-stepping through the code

[issue17998] internal error in regular expression engine

2013-05-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Here is a patch which should fix this bug. I still have to look for similar bugs and write tests. -- keywords: +patch stage: - patch review versions: +Python 3.3, Python 3.4 Added file: http://bugs.python.org/file30299/re_unsigned_ptrdiff.patch

[issue17998] internal error in regular expression engine

2013-05-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Thank you Matthew for simpler examples. They helped and I'll use them in the tests. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17998 ___

Re: Regular expression problem

2013-03-11 Thread jmfauth
On 11 mar, 03:06, Terry Reedy tjre...@udel.edu wrote: ... By teaching 'speed before correctness, this site promotes bad programming habits and thinking (and the use of low-level but faster languages). ... This is exactly what your flexible string representation does! And away from

Re: Regular expression problem

2013-03-11 Thread Mark Lawrence
On 11/03/2013 09:28, jmfauth wrote: On 11 mar, 03:06, Terry Reedy tjre...@udel.edu wrote: ... By teaching 'speed before correctness, this site promotes bad programming habits and thinking (and the use of low-level but faster languages). ... This is exactly what your flexible string

Re: Regular expression problem

2013-03-11 Thread rusi
On Mar 11, 2:28 pm, jmfauth wxjmfa...@gmail.com wrote: On 11 mar, 03:06, Terry Reedy tjre...@udel.edu wrote: ... By teaching 'speed before correctness, this site promotes bad programming habits and thinking (and the use of low-level but faster languages). ... This is exactly what

On topic, please [Was:Re: Regular expression problem]

2013-03-11 Thread Ned Deily
A friendly reminder that this forum is for general discussion and questions about Python. Pretty much anything Python-related is fair game for discussion, and the group is even fairly tolerant of off-topic digressions; there have been entertaining discussions of topics such as floating point,

Re: Regular expression problem

2013-03-11 Thread Serhiy Storchaka
On 11.03.13 04:06, Terry Reedy wrote: On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all

Re: Regular expression problem

2013-03-11 Thread Terry Reedy
On 3/11/2013 2:30 PM, Serhiy Storchaka wrote: On 11.03.13 04:06, Terry Reedy wrote: On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python

Regular expression problem

2013-03-10 Thread mukesh tiwari
Hello all I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please tell me how to make this code run faster. import re if __name__ == __main__: n = int ( raw_input() ) c = 1 while c = n

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com wrote: I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please tell me how to make this code run faster. What is the time limit? I

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:59 AM, Chris Angelico ros...@gmail.com wrote: On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com wrote: I am trying to solve this problem[1] using regular expression. I wrote this code but I am getting time limit exceed. Could some one please

Re: Regular expression problem

2013-03-10 Thread mukesh tiwari
Hi Chris On the problem page, it is 3 second. What is the time limit? I just tried it (Python 2.6 under Windows) and it finished in a humanly-immeasurable amount of time. Are you sure that STDIN (eg raw_input()) is where your test data is coming from? Yes, on SPOJ we read data from

Re: Regular expression problem

2013-03-10 Thread mukesh tiwari
Hi Chris Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! import re if __name__ == __main__: n = int ( raw_input() ) c = 1 while c = n : email = filter ( lambda x : x != None , [

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 5:48 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com wrote: Hi Chris Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! Excellent! Have fun. Incidentally, regular expressions

Re: Regular expression problem

2013-03-10 Thread Terry Reedy
On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all languages. Thus, a 'slow' python

how to right the regular expression ?

2013-02-14 Thread python
my tv.txt is : http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio31 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放)

Re: how to right the regular expression ?

2013-02-14 Thread MRAB
On 2013-02-14 14:13, python wrote: my tv.txt is : http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放) http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放) http://202.177.192.119/radio31

Re:Re: how to right the regular expression ?

2013-02-14 Thread python
the regex--- pat = r'([a-z].+?\s)(.+)(?:(\(.+\)))?' ,do not work at all. rfile.close() import re rfile=open(tv.txt,r) pat1 = r'([a-z].+?\s)(.+)((\(.+\)))?' for line in rfile.readlines(): ... Match=re.match(pat1,line) ... print 1group is ,Match.group(1),2group is

Re: how to right the regular expression ?

2013-02-14 Thread MRAB
On 2013-02-15 00:32, python wrote: the regex--- pat = r'([a-z].+?\s)(.+?)((\(.+\)))?$' ,do not work at all. [snip] Sorry, that should be: pat1 = r'([a-z].+?\s)(.+?)((\(.+\)))?$' Group 2 should've been lazy (.+?), and because of that it should've forced matching the end of the line with $.

[issue17087] Improve the repr for regular expression match objects

2013-01-31 Thread Ezio Melotti
Ezio Melotti added the comment: #13592 is indeed the issue I was thinking about, but apparently that's about _sre.SRE_Pattern, so it's not the same thing. Just showing group(0) should be helpful. Often the interesting group is group(1), so showing only group(0) seems a bit arbitrary. And

[issue17087] Improve the repr for regular expression match objects

2013-01-30 Thread Raymond Hettinger
() 12 mo.group(0) '3/14/2013' However, this gets old when experimenting with alternative regular expressions. A better solution is to improve the repr: re.search(r'\d+/\d+/\d+', s) SRE Match object: start=3, stop=12, group(0)='3/14/2013' This would make the regular expression

[issue17087] Improve the repr for regular expression match objects

2013-01-30 Thread Ezio Melotti
Ezio Melotti added the comment: Showing start and stop would be OK, but there might be many groups and they might contain lot of text, so they can't simply be included in the repr as they are. FWIW there was another issue about changing _sre.SRE_Match to something better, but I can't find it

[issue17087] Improve the repr for regular expression match objects

2013-01-30 Thread Chris Jerdonek
Chris Jerdonek added the comment: Is this a duplicate of issue 13592? -- nosy: +chris.jerdonek ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue17087 ___

[issue17087] Improve the repr for regular expression match objects

2013-01-30 Thread Raymond Hettinger
Raymond Hettinger added the comment: Just showing group(0) should be helpful. And perhaps the number of groups. If a string is really long, we can truncate it like reprlib does. The main goal is to make it easier to work with match objects at the interactive prompt. They are currently too

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread iMath
在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道: I only know the dollar sign ($) will match a pattern from the end of a string,but which method does it work with ,re.match() or re.search() ? I thought re.match('h.$', 'hbxihi') will match ‘hi’ ,but it does not .so why ? --

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 01:45:58 -0800, iMath wrote: 在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道: I only know the dollar sign ($) will match a pattern from the end of a string,but which method does it work with ,re.match() or re.search() ? I thought re.match('h.$', 'hbxihi') will match ‘hi’

Re: Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-04 Thread someone
one leading letter or underscore [a-z_] plus at least two letters, underscores or digits [a-z0-9_]{2,30} Ah, [a-z0-9_]{2,30} means there should be at least two characters and maximum 30 characters here ? Yes. See http://docs.python.org/2/library/re.html#regular-expression-syntax Thanks

Regular expression syntax, was Re: pylint, was Re: pygame - importing GL - very bad...

2013-01-03 Thread Peter Otten
] plus at least two letters, underscores or digits [a-z0-9_]{2,30} Ah, [a-z0-9_]{2,30} means there should be at least two characters and maximum 30 characters here ? Yes. See http://docs.python.org/2/library/re.html#regular-expression-syntax -- http://mail.python.org/mailman/listinfo/python

[issue16443] Add docstrings to regular expression match objects

2012-12-25 Thread Andrew Svetlov
Andrew Svetlov added the comment: Fixed in #16760 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16443 ___ ___ Python-bugs-list mailing list

[issue16443] Add docstrings to regular expression match objects

2012-12-24 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: `MatchObject` term is not defined anywhere in the documentation. It will be better to use `match object` instead. -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org

[issue16443] Add docstrings to regular expression match objects

2012-12-23 Thread Anton Kasyanov
Anton Kasyanov added the comment: Created a patch with docstrings for match objects. Also added empty lines in pattern object docstrings according to http://www.python.org/dev/peps/pep-0007/#id7 -- keywords: +patch nosy: +a.kasyanov, asvetlov versions: -Python 2.7 Added file:

[issue16443] Add docstrings to regular expression match objects

2012-12-23 Thread Roundup Robot
Roundup Robot added the comment: New changeset e4f1b3565509 by Andrew Svetlov in branch '3.2': Issue #16443: Add docstrings to regular expression match objects. http://hg.python.org/cpython/rev/e4f1b3565509 New changeset 64e050c2d010 by Andrew Svetlov in branch '3.3': Issue #16443: Add

[issue16443] Add docstrings to regular expression match objects

2012-12-23 Thread Roundup Robot
Roundup Robot added the comment: New changeset c390dc999fcc by Andrew Svetlov in branch '2.7': Issue #16443: Add docstrings to regular expression match objects. http://hg.python.org/cpython/rev/c390dc999fcc -- ___ Python tracker rep

[issue16443] Add docstrings to regular expression match objects

2012-12-23 Thread Andrew Svetlov
Andrew Svetlov added the comment: Pushed. Thank you, Anton! -- resolution: - fixed stage: needs patch - committed/rejected status: open - closed versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16443

Regular expression for different date formats in Python

2012-11-26 Thread undesputed . hackerz
Hello Developers, I am a beginner in python and need help with writing a regular expression for date and time to be fetched from some html documents. In the following code I am walking through the html files in a folder called event and printing the headings with h1 tag using beautifulsoup

Re: Regular expression for different date formats in Python

2012-11-26 Thread Michael Torrie
On 11/26/2012 06:15 AM, undesputed.hack...@gmail.com wrote: I am a beginner in python and need help with writing a regular expression for date and time to be fetched from some html documents. Would the parser module from the third-party dateutil module work for you? http://pypi.python.org/pypi

Re: Regular expression for different date formats in Python

2012-11-26 Thread Miki Tebeka
On Monday, November 26, 2012 8:34:22 AM UTC-8, Michael Torrie wrote: http://pypi.python.org/pypi/python-dateutil ... I don't believe the library is updated for Python 3 yet, sadly. dateutil supports 3.x since version 2.0. -- http://mail.python.org/mailman/listinfo/python-list

[issue16443] Add docstrings to regular expression match objects

2012-11-09 Thread Ezio Melotti
Ezio Melotti added the comment: Do you mean http://docs.python.org/2/library/re.html#match-objects ? This doesn't seem to say anything too useful. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16443

[issue16443] Add docstrings to regular expression match objects

2012-11-08 Thread Raymond Hettinger
keywords: easy messages: 175188 nosy: docs@python, rhettinger priority: normal severity: normal status: open title: Add docstrings to regular expression match objects type: enhancement versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4 ___ Python

[issue16443] Add docstrings to regular expression match objects

2012-11-08 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- components: +Regular Expressions nosy: +ezio.melotti, mrabarnett stage: - needs patch versions: -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16443

Re: + in regular expression

2012-10-09 Thread Duncan Booth
than following a grammar (_parse is a 238 line function). So I think it really is just trying to match existing regular expression parsers and any possible grammar is an excuse for why it should be the way it is rather than an explanation. -- Duncan Booth http://kupuguy.blogspot.com -- http

Re: + in regular expression

2012-10-05 Thread Duncan Booth
issue in the grammar. (\s{6})+ is also accepted. It's about syntax, not precedence, but the documentation doesn't really spell it out in full. Like most regex documentation it talks in woolly terms about special characters rather than giving a formal syntax. A regular expression element may

Re: Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you can follow an element with two quantifiers

Re: + in regular expression

2012-10-05 Thread Evan Driscoll
On 10/05/2012 10:27 AM, Evan Driscoll wrote: On 10/05/2012 04:23 AM, Duncan Booth wrote: A regular expression element may be followed by a quantifier. Quantifiers are '*', '+', '?', '{n}', '{n,m}' (and lazy quantifiers '*?', '+?', '{n,m}?'). There's nothing in the regex language which says you

<    1   2   3   4   5   6   7   8   9   10   >