Re: [Tutor] Regular expression on python

2015-04-15 Thread Alan Gauld
On 15/04/15 09:24, Peter Otten wrote: function call. I've never seen (or noticed?) the embedded form, and don't see it described in the docs anywhere Quoting : """ (?aiLmsux) (One or more letters from the set 'a', 'i', 'L', 'm', 's', 'u', 'x'.) The

Re: [Tutor] Regular expression on python

2015-04-15 Thread Peter Otten
Albert-Jan Roskam wrote: > On Tue, 4/14/15, Peter Otten <__pete...@web.de> wrote: >>> >>> pprint.pprint( >>> ... [(k, int(v)) for k, v in >>> ... >re.compile(r"(.+?):\s+(\d+)(?:\s+\(.*?\))?\s*").findall(line)]) >>> [('Input Read Pairs', 2127436), >>>('Both Surviving', 1795091), >>>('Forward Only

Re: [Tutor] Regular expression on python

2015-04-15 Thread Albert-Jan Roskam
On Tue, 4/14/15, Peter Otten <__pete...@web.de> wrote: Subject: Re: [Tutor] Regular expression on python To: tutor@python.org Date: Tuesday, April 14, 2015, 4:37 PM Steven D'Aprano wrote: > On Tue, Apr 14, 2015 at 10:00:47AM +020

Re: [Tutor] Regular expression on python

2015-04-15 Thread Peter Otten
Alan Gauld wrote: > On 15/04/15 02:02, Steven D'Aprano wrote: >>> New one on me. Where does one find out about verbose mode? >>> I don't see it in the re docs? >>> > >> or embed the flag in the pattern. The flags that I know of are: >> >> (?x) re.X re.VERBOSE >> >> The flag can appear anywhere in

Re: [Tutor] Regular expression on python

2015-04-15 Thread Alan Gauld
On 15/04/15 02:02, Steven D'Aprano wrote: New one on me. Where does one find out about verbose mode? I don't see it in the re docs? or embed the flag in the pattern. The flags that I know of are: (?x) re.X re.VERBOSE The flag can appear anywhere in the pattern and applies to the whole patte

Re: [Tutor] Regular expression on python

2015-04-14 Thread Alex Kleider
On 2015-04-14 16:49, Alan Gauld wrote: New one on me. Where does one find out about verbose mode? I don't see it in the re docs? This is where I go whenever I find myself having to (re)learn the details of regex: https://docs.python.org/3/howto/regex.html I believe a '2' can be substituted

Re: [Tutor] Regular expression on python

2015-04-14 Thread Steven D'Aprano
On Wed, Apr 15, 2015 at 12:49:26AM +0100, Alan Gauld wrote: > New one on me. Where does one find out about verbose mode? > I don't see it in the re docs? > > I see an re.X flag but while it seems to be similar in purpose > yet it is different to your style above (no parens for example)? I presum

Re: [Tutor] Regular expression on python

2015-04-14 Thread Mark Lawrence
On 15/04/2015 00:49, Alan Gauld wrote: On 14/04/15 13:21, Steven D'Aprano wrote: although I would probably want to write it out in verbose mode just in case the requirements did change: r"""(?x)(?# verbose mode) (.+?): (?# capture one or more character, followed by a colon) \s+

Re: [Tutor] Regular expression on python

2015-04-14 Thread Alan Gauld
On 14/04/15 13:21, Steven D'Aprano wrote: although I would probably want to write it out in verbose mode just in case the requirements did change: r"""(?x)(?# verbose mode) (.+?): (?# capture one or more character, followed by a colon) \s+ (?# one or more whitespace) (\

Re: [Tutor] Regular expression on python

2015-04-14 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, Apr 14, 2015 at 10:00:47AM +0200, Peter Otten wrote: >> Steven D'Aprano wrote: > >> > I swear that Perl has been a blight on an entire generation of >> > programmers. All they know is regular expressions, so they turn every >> > data processing problem into a regu

Re: [Tutor] Regular expression on python

2015-04-14 Thread Steven D'Aprano
On Tue, Apr 14, 2015 at 10:00:47AM +0200, Peter Otten wrote: > Steven D'Aprano wrote: > > I swear that Perl has been a blight on an entire generation of > > programmers. All they know is regular expressions, so they turn every > > data processing problem into a regular expression. Or at least they

Re: [Tutor] Regular expression on python

2015-04-14 Thread Peter Otten
Steven D'Aprano wrote: > On Mon, Apr 13, 2015 at 02:29:07PM +0200, jarod...@libero.it wrote: >> Dear all. >> I would like to extract from some file some data. >> The line I'm interested is this: >> >> Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward >> Only Surviving: 17315 (0.8

Re: [Tutor] Regular expression on python

2015-04-13 Thread Steven D'Aprano
On Mon, Apr 13, 2015 at 02:29:07PM +0200, jarod...@libero.it wrote: > Dear all. > I would like to extract from some file some data. > The line I'm interested is this: > > Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward > Only Surviving: 17315 (0.81%) Reverse Only Surviving: 641

Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld
On 13/04/15 19:42, Alan Gauld wrote: if lines.startswith("Input"): tp = lines.split("\t") print re.findall("Input\d",str(tp)) Input is not followed by a number. You need a more powerful pattern. Which is why I recommend trying to solve it as far as possible w

Re: [Tutor] Regular expression on python

2015-04-13 Thread Alan Gauld
On 13/04/15 13:29, jarod...@libero.it wrote: Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 (14.51%) Its not clear where the tabs are in this line. But if they are after the numbers, like s

[Tutor] Regular expression on python

2015-04-13 Thread jarod...@libero.it
Dear all. I would like to extract from some file some data. The line I'm interested is this: Input Read Pairs: 2127436 Both Surviving: 1795091 (84.38%) Forward Only Surviving: 17315 (0.81%) Reverse Only Surviving: 6413 (0.30%) Dropped: 308617 (14.51%) with open("255.trim.log","r") as p: