Re: issue with regular expressions

2019-10-22 Thread joseph pareti
Ok, thanks. It works for me. regards, Am Di., 22. Okt. 2019 um 11:29 Uhr schrieb Matt Wheeler : > > > On Tue, 22 Oct 2019, 09:44 joseph pareti, wrote: > >> the following code ends in an exception: >> >> import re >> pattern = 'Sottoscrizione unica soluzione' >> mylines = []

Re: issue with regular expressions

2019-10-22 Thread Matt Wheeler
On Tue, 22 Oct 2019, 09:44 joseph pareti, wrote: > the following code ends in an exception: > > import re > pattern = 'Sottoscrizione unica soluzione' > mylines = []# Declare an empty list. with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading tex

issue with regular expressions

2019-10-22 Thread joseph pareti
the following code ends in an exception: import re pattern = 'Sottoscrizione unica soluzione' mylines = []# Declare an empty list. with open ('tmp.txt', 'rt') as myfile: # Open tmp.txt for reading text. for myline in myfile: # For each lin

Re: regular expressions help

2019-09-20 Thread Barry Scott
When I'm debugging a regex I make the regex shorter and shorter to figure out what the problem is. Try starting with re.compile(r'm') and then add the chars one by one seeing what happens as the string gets longer. Barry > On 19 Sep 2019, at 09:41, Pradeep Patra wrote: > > I am using python 2

Re: regular expressions help

2019-09-19 Thread Chris Angelico
tead of passing my-dog i can pass my-cat or blah blah. I am thinking of > creating a list of probable combinations to search from the list. Anybody > have better ideas? > If you just want to find a string in another string, don't use regular expressions at all! Just ask Python dir

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
Thanks David /Anthony for your help. I figured out the issue myself. I dont need any ^, $ etc to the regex pattern and the plain string (for exp my-dog) works fine. I am looking at creating a generic method so that instead of passing my-dog i can pass my-cat or blah blah. I am thinking of creating

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 19:34, Pradeep Patra wrote: > Thanks David for your quick help. Appreciate it. When I tried on python 2.7.3 > the same thing you did below I got the error after matches.group(0) as > follows: > > AttributeError: NoneType object has no attribute 'group'. > > I tried to che

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
Thanks David for your quick help. Appreciate it. When I tried on python 2.7.3 the same thing you did below I got the error after matches.group(0) as follows: AttributeError: NoneType object has no attribute 'group'. I tried to check 'None' for no match for re.search as the documentation says but

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 18:41, Pradeep Patra wrote: > On Thursday, September 19, 2019, Pradeep Patra > wrote: >> On Thursday, September 19, 2019, David wrote: >>> On Thu, 19 Sep 2019 at 17:51, Pradeep Patra >>> wrote: >>> > pattern=re.compile(r'^my\-dog$') >>> > matches = re.search(mystr) >>

Re: regular expressions help

2019-09-19 Thread Pradeep Patra
I am using python 2.7.6 but I also tried on python 3.7.3. On Thursday, September 19, 2019, Pradeep Patra wrote: > Beginning of the string. But I tried removing that as well and it still > could not find it. When I tested at www.regex101.com and it matched > successfully whereas I may be wrong. C

Re: regular expressions help

2019-09-19 Thread David
On Thu, 19 Sep 2019 at 17:51, Pradeep Patra wrote: > > pattern=re.compile(r'^my\-dog$') > matches = re.search(mystr) > > In the above example both cases(match/not match) the matches returns "None" Hi, do you know what the '^' character does in your pattern? -- https://mail.python.org/mailman/lis

regular expressions help

2019-09-19 Thread Pradeep Patra
Hi all, I was playing around with regular expressions and testing the simple regular expression and its notworking for some reason. I want to search "my-dog" at any of the place in a string and return the index but its not working. I tried both in python 3.7.3 and 2.7.x. Can anyone p

Re: Regular Expressions, Speed, Python, and NFA

2017-04-17 Thread breamoreboy
On Friday, April 14, 2017 at 4:12:27 PM UTC+1, Malik Rumi wrote: > I am running some tests using the site regex101 to figure out the correct > regexs to use for a project. I was surprised at how slow it was, constantly > needing to increase the timeouts. I went Googling for a reason, and solution

Re: Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Rob Gaddi
way in terms of programmer time is to pipe out to grep or awk on this one. Kirk Sluder Thanks. I'll also throw in the obligatory quote from Jamie Zawinsky, "Some people, when confronted with a problem, think 'I know, I'll use regular expressions.' Now they have two pr

Re: Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Peter Otten
Malik Rumi wrote: > I am running some tests using the site regex101 to figure out the correct > regexs to use for a project. I was surprised at how slow it was, > constantly needing to increase the timeouts. I went Googling for a reason, > and solution, and found Russ Cox’s article from 2007: > ht

RE: Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Joseph L. Casale
-Original Message- From: Python-list [mailto:python-list- bounces+jcasale=activenetwerx@python.org] On Behalf Of Malik Rumi Sent: Friday, April 14, 2017 9:12 AM To: python-list@python.org Subject: Regular Expressions, Speed, Python, and NFA > I am running some tests using the s

Re: Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Steve D'Aprano
On Sat, 15 Apr 2017 01:12 am, Malik Rumi wrote: > I couldn’t understand why, if this was even remotely correct, > we don’t use NFA in Python [...] > I don’t think I’m qualified to take on the idea of creating > a new NFA module for Python. If not you, then who should do it? Python is open so

Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Malik Rumi
I am running some tests using the site regex101 to figure out the correct regexs to use for a project. I was surprised at how slow it was, constantly needing to increase the timeouts. I went Googling for a reason, and solution, and found Russ Cox’s article from 2007: https://swtch.com/~rsc/rege

Re: Regular expressions

2015-11-06 Thread rurpy--- via Python-list
>> think it is an improvement. > > > >I don't understand this. This is like saying "so far the only use I have for > >a sandwich press is to replace my coffee pot". Regular expressions and > >slicing do very different things. > >[...] > > Here is a

Re: Regular expressions

2015-11-06 Thread Larry Martell
On Fri, Nov 6, 2015 at 3:36 PM, Christian Gollwitzer wrote: > Am 06.11.15 um 20:52 schrieb ru...@yahoo.com: >> >> I have always thought lexing >> and parsing solutions for Python were a weak spot in the Python eco- >> system and I was about to write that I would love to see a PEG parser >> for pyt

Re: Regular expressions

2015-11-06 Thread Christian Gollwitzer
Am 06.11.15 um 20:52 schrieb ru...@yahoo.com: I have always thought lexing and parsing solutions for Python were a weak spot in the Python eco- system and I was about to write that I would love to see a PEG parser for python when I saw this: http://fdik.org/pyPEG/ Unfortunately it suffers from

Re: Regular expressions

2015-11-06 Thread rurpy--- via Python-list
On 11/05/2015 01:18 AM, Christian Gollwitzer wrote: > Am 05.11.15 um 06:59 schrieb rurpy: >>> Can you call yourself a well-rounded programmer without at least >>> a basic understanding of some regex library? Well, probably not. >>> But that's part of the problem with regexes. They have, to some >>>

Re: Regular expressions

2015-11-05 Thread Seymore4Head
"so far the only use I have for >a sandwich press is to replace my coffee pot". Regular expressions and >slicing do very different things. > >Slicing extracts substrings, given known starting and ending positions: > > >py> the_str = "Now is the time for all good m

Re: Regular expressions

2015-11-05 Thread Tim Chase
On 2015-11-05 23:05, Steven D'Aprano wrote: > Oh the shame, I knew that. Somehow I tangled myself in a knot, > thinking that it had to be 1 *followed by* zero or more characters. > But of course it's not a glob, it's a regex. But that's a good reminder of fnmatch/glob modules too. Sometimes all y

Re: Regular expressions

2015-11-05 Thread Albert van der Horst
ng? How does "4" >match "1*"? >> which surprised me because I remembered that there usually weren't any >> matching lines when I invoked grep instead of egrep by mistake. So I tried >> another one >> >> $ seq 5 | grep '[1-3]+'

Re: Regular expressions

2015-11-05 Thread Steven D'Aprano
On Thu, 5 Nov 2015 07:33 pm, Peter Otten wrote: > Steven D'Aprano wrote: > >> On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: >> >>> I tried Tim's example >>> >>> $ seq 5 | grep '1*' >>> 1 >>> 2 >>> 3 >>> 4 >>> 5 >>> $ >> >> I don't understand this. What on earth is grep matching? How does "4"

Re: Regular expressions

2015-11-05 Thread Antoon Pardon
that ends with a '*' with a regular expression. What almost noone seems to have considered is that the real problem might have been more involved and an excellent example of a problem you can solve with regular expressions but that there was this subproblem of recognizing a '*' at the

Re: Regular expressions

2015-11-05 Thread Peter Otten
hat there usually weren't any >> matching lines when I invoked grep instead of egrep by mistake. So I >> tried another one >> >> $ seq 5 | grep '[1-3]+' >> $ >> >> and then headed for the man page. Apparently there is a subset called >> &quo

Re: Regular expressions

2015-11-05 Thread Christian Gollwitzer
Am 05.11.15 um 06:59 schrieb ru...@yahoo.com: Can you call yourself a well-rounded programmer without at least a basic understanding of some regex library? Well, probably not. But that's part of the problem with regexes. They have, to some degree, driven out potentially better -- or at least diff

Re: Regular expressions

2015-11-05 Thread Chris Angelico
ne golf: Find the shortest regex that matches the names of all GNU commands which accept regular expressions, and no other commands! ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-05 Thread Gregory Ewing
Tim Chase wrote: You get even crazier when you start adding zgrep/zegrep/zfgrep. It's fitting somehow that we should need an RE to describe all the possible names of the grep command. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
On Wednesday, November 4, 2015 at 7:46:24 PM UTC-7, Chris Angelico wrote: > On Thu, Nov 5, 2015 at 11:24 AM, rurpy wrote: > The "take away" that I recommend is: Rurpy loves to argue in favour of > regular expressions, No, I don't love it, I quite dislike it. > but as

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
closer to indispensable. By my count there are 2377. That's counting rpn languages where it is 1 1 +. If you don't count them it is 2250. > - How many languages make regular expressions a built-in part of the > language? Almost none of them. There's Perl, obviously, and its &

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
On Wednesday, November 4, 2015 at 7:31:34 PM UTC-7, Steven D'Aprano wrote: > On Thu, 5 Nov 2015 11:13 am, rurpy wrote: > > > There would be far fewer computer languages, and they would be much > > more primitive if regular expressions (and the fundamental concepts > &g

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
>>> than "using" a computer: editing, sending email etc. Many computer >>>> users (not programmers) learn to use regular expressions as part >>>> of using a computer without knowing anything about programming. >>>> It was on that basis I called

Re: Regular expressions

2015-11-04 Thread Ben Finney
Steven D'Aprano writes: > Yes yes, I know that regexes aren't the only tool in my tool box, but > *right now* I want to learn how to use regexes. I'll gently suggest this isn't a particularly good forum to do so. Learn them with a tool like http://www.regexr.com/> and a tutorial http://www.usna

Re: Regular expressions

2015-11-04 Thread Ben Finney
Steven D'Aprano writes: > On Wed, 4 Nov 2015 07:57 pm, Peter Otten wrote: > > > I tried Tim's example > > > > $ seq 5 | grep '1*' > > 1 > > 2 > > 3 > > 4 > > 5 > > $ > > I don't understand this.

Re: Regular expressions

2015-11-04 Thread Tim Chase
On 2015-11-05 13:28, Steven D'Aprano wrote: > > I tried Tim's example > > > > $ seq 5 | grep '1*' > > 1 > > 2 > > 3 > > 4 > > 5 > > $ > > I don't understand this. What on earth is grep matching? How does > "4" match "1*"? The line with "4" matches "zero or more 1s". If it was searching for a

Re: Regular expressions

2015-11-04 Thread Chris Angelico
lks here are often way > overly negative regarding regular expressions and that you not > ignore them, but take them with a BIG grain of salt and continue > learning about and using regexs. > > You will find they are an indispensable tool, not just in Python > programming but in many

Re: Regular expressions

2015-11-04 Thread Steven D'Aprano
On Thu, 5 Nov 2015 11:13 am, ru...@yahoo.com wrote: > There would be far fewer computer languages, and they would be much > more primitive if regular expressions (and the fundamental concepts > that they express) did not exist. Well, that's certainly true. But only because

Re: Regular expressions

2015-11-04 Thread Steven D'Aprano
e because I remembered that there usually weren't any > matching lines when I invoked grep instead of egrep by mistake. So I tried > another one > > $ seq 5 | grep '[1-3]+' > $ > > and then headed for the man page. Apparently there is a subset called > "ba

Re: Regular expressions

2015-11-04 Thread Steven D'Aprano
ilt-in part of the language? Almost all of them. I don't know of any language that doesn't let you express something like "1 + 1" using built-in functions or syntax. Arithmetic is much closer to indispensable. - How many languages make regular expressions a built-in part of th

Re: Regular expressions

2015-11-04 Thread Steven D'Aprano
On Thu, 5 Nov 2015 10:02 am, Seymore4Head wrote: > So far the only use I have for regex is to replace slicing, but I > think it is an improvement. I don't understand this. This is like saying "so far the only use I have for a sandwich press is to replace my coffee pot". Re

Re: Regular expressions

2015-11-04 Thread Chris Angelico
t clear. I was not talking about computer >>> science. I was talking about human beings learning about computers. >>> Most people I know consider programming to be a higher level activity >>> than "using" a computer: editing, sending email etc. Many computer &g

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
On Wednesday, November 4, 2015 at 4:05:06 PM UTC-7, Seymore4Head wrote: >[...] > I am still here, but I have to admit I am not picking up too much. The "take away" I recommend is: the folks here are often way overly negative regarding regular expressions and that you not ignor

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
uman beings learning about computers. >> Most people I know consider programming to be a higher level activity >> than "using" a computer: editing, sending email etc. Many computer >> users (not programmers) learn to use regular expressions as part >> of using a

Re: Regular expressions

2015-11-04 Thread Seymore4Head
On Wed, 4 Nov 2015 18:08:51 -0500, Terry Reedy wrote: >On 11/3/2015 10:23 PM, Steven D'Aprano wrote: > >> I don't even know what grep stands for. > >Get Regular Expression & Print Thanks, I may get around to that eventually. -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-04 Thread Seymore4Head
prove me wrong. All you would need to do to >demonstrate that regexes are more fundamental than branching, loops and >variables would be to demonstrate that the primitive operations available in >commonly used CPUs are regular expressions, and that (for example) C's for >loo

Re: Regular expressions

2015-11-04 Thread Terry Reedy
On 11/3/2015 10:23 PM, Steven D'Aprano wrote: I don't even know what grep stands for. Get Regular Expression & Print -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-04 Thread Seymore4Head
On Wed, 04 Nov 2015 08:13:51 -0700, Michael Torrie wrote: >On 11/04/2015 01:57 AM, Peter Otten wrote: >> and then headed for the man page. Apparently there is a subset >> called "basic regular expressions": >> >> """> Basic vs Extended Reg

Re: What does “grep” stand for? (was: Regular expressions)

2015-11-04 Thread Tim Chase
On 2015-11-05 05:24, Ben Finney wrote: > A very common command to issue, then, is “actually show me the line > of text I just specified”; the ‘p’ (for “print”) command. > > Another very common command is “find the text matching this pattern > and perform these commands on it”, which is ‘g’ (for “g

What does “grep” stand for? (was: Regular expressions)

2015-11-04 Thread Ben Finney
Steven D'Aprano writes: > On Wednesday 04 November 2015 13:55, Dan Sommers wrote: > > > Its very name indicates that its default mode most certainly is > > regular expressions. > > I don't even know what grep stands for. “grep” stands for ‘g/RE/p’. The

Re: Regular expressions

2015-11-04 Thread Tim Chase
On 2015-11-04 09:57, Peter Otten wrote: > Well, I didn't know that grep uses regular expressions by default. It doesn't help that grep(1) comes in multiple flavors: grep: should use BRE (Basic REs) fgrep: same as "grep -F"; uses fixed strings, no REs egrep: same

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-04 Thread Tim Chase
On 2015-11-04 14:39, Steven D'Aprano wrote: > On Wednesday 04 November 2015 03:56, Tim Chase wrote: >> Or even more valuable to me: >> >> with open(..., newline="strip") as f: >> assert all(not line.endswith(("\n", "\r")) for line in f) > > # Works only on Windows text files. > def chomp(li

Re: Regular expressions

2015-11-04 Thread Michael Torrie
On 11/04/2015 01:57 AM, Peter Otten wrote: > and then headed for the man page. Apparently there is a subset > called "basic regular expressions": > > """> Basic vs Extended Regular Expressions >In basic regular expressions the meta-characte

Re: Regular expressions

2015-11-04 Thread Chris Angelico
Most people I know consider programming to be a higher level activity > than "using" a computer: editing, sending email etc. Many computer > users (not programmers) learn to use regular expressions as part > of using a computer without knowing anything about programming. > It

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
On Wednesday, November 4, 2015 at 1:52:31 AM UTC-7, Steven D'Aprano wrote: > On Wednesday 04 November 2015 18:21, Christian Gollwitzer wrote: > > > What rurpy meant, was that regexes can surface to a computer user > > earlier than variables and branches; a user who does not go into the > > depth t

Re: Regular expressions

2015-11-04 Thread rurpy--- via Python-list
l you would need to do to > demonstrate that regexes are more fundamental than branching, loops and > variables would be to demonstrate that the primitive operations available in > commonly used CPUs are regular expressions, and that (for example) C's for > loop and if...else

Re: Regular expressions

2015-11-04 Thread Grant Edwards
On 2015-11-04, Michael Torrie wrote: > On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >> >>>> Grep can use regular expressions (and I do so with it regularly), but >>>> it's default mode is certainly not regular expressions ... >>> >>>

Re: Regular expressions

2015-11-04 Thread Antoon Pardon
Op 04-11-15 om 04:35 schreef Steven D'Aprano: > On Wednesday 04 November 2015 03:20, Chris Angelico wrote: > >> (So, >> too, are all the comments about using [-1] or string methods. But we >> weren't to know that.) > If MRAB could understand what he wanted, I'm sure most others could have > too.

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-04 Thread Oscar Benjamin
On 4 November 2015 at 03:39, Steven D'Aprano wrote: > > Better would be this: > > def chomp(lines): > for line in lines: > yield line.rstrip() # remove all trailing whitespace > > > with open(...) as f: > for line in chomp(f): ... with open(...) as f: for line in map(str.rstr

Re: Regular expressions

2015-11-04 Thread Peter Otten
Michael Torrie wrote: > On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >>>> Grep can use regular expressions (and I do so with it regularly), but >>>> it's default mode is certainly not regular expressions ... >>> >>> Its very name in

Re: Regular expressions

2015-11-04 Thread Steven D'Aprano
any problem you can solve using a program written in (say) Python, C, Lisp, Smalltalk, etc, or execute on a CPU (or simulate in your head!) could be written as a sufficiently complex regular expression. I think he is *technically wrong*, if by "regex" we mean actual regular express

Re: Regular expressions

2015-11-03 Thread Christian Gollwitzer
Am 04.11.15 um 04:48 schrieb Steven D'Aprano: On Wednesday 04 November 2015 11:33, ru...@yahoo.com wrote: Not quite. Core language concepts like ifs, loops, functions, variables, slicing, etc are the socket wrenches of the programmer's toolbox. Regexs are like an electric impact socket wrench

Re: Regular expressions

2015-11-03 Thread Nobody
On Wed, 04 Nov 2015 14:23:04 +1100, Steven D'Aprano wrote: >> Its very name indicates that its default mode most certainly is regular >> expressions. > > I don't even know what grep stands for. >From the ed command "g /re/p" (where "re" i

Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
nstrate that the primitive operations available in commonly used CPUs are regular expressions, and that (for example) C's for loop and if...else are implemented in machine code as regular expressions, rather than the other way around. -- Steve -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-03 Thread Michael Torrie
On 11/03/2015 08:23 PM, Steven D'Aprano wrote: >>> Grep can use regular expressions (and I do so with it regularly), but >>> it's default mode is certainly not regular expressions ... >> >> Its very name indicates that its default mode most certainly is r

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 03:56, Tim Chase wrote: > Or even more valuable to me: > > with open(..., newline="strip") as f: > assert all(not line.endswith(("\n", "\r")) for line in f) # Works only on Windows text files. def chomp(lines): for line in lines: yield line.rstrip(

Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
On Wednesday 04 November 2015 03:20, Chris Angelico wrote: > On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head > wrote: >> Yes I knew that -1 represents the end character. It is not a question >> of trying to accomplish anything. I was just practicing with regex >> and wasn't sure how to express a *

Re: Regular expressions

2015-11-03 Thread Steven D'Aprano
se them: consider grep, sed, a zillion editors, database query >>> languages, etc. >> >> Grep can use regular expressions (and I do so with it regularly), but >> it's default mode is certainly not regular expressions ... > > Its very name indicates that its defa

Re: Regular expressions

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 2:12 PM, Tim Chase wrote: > It's not as helpful as one might hope because you're stuck using a > fixed regexp rather than an arbitrary regexp, but if you have a > particular regexp you search for frequently, you can index it. > Otherwise, you'd be doing full table-scans (or

Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 19:04, Michael Torrie wrote: > Grep can use regular expressions (and I do so with it regularly), > but it's default mode is certainly not regular expressions, and it > is still very powerful. I suspect you're thinking of `fgrep` (AKA "grep -F") which u

Re: Regular expressions

2015-11-03 Thread Dan Sommers
tc. > > Grep can use regular expressions (and I do so with it regularly), but > it's default mode is certainly not regular expressions ... Its very name indicates that its default mode most certainly is regular expressions. Dan -- https://mail.python.org/mailman/listinfo/python-list

Re: Regular expressions

2015-11-03 Thread Michael Torrie
On 11/03/2015 05:33 PM, rurpy--- via Python-list wrote: > I consider regexs more fundemental. One need not even be a programmer > to use them: consider grep, sed, a zillion editors, database query > languages, etc. Grep can use regular expressions (and I do so with it regularly),

Re: Regular expressions

2015-11-03 Thread rurpy--- via Python-list
On Monday, November 2, 2015 at 9:38:24 PM UTC-7, Michael Torrie wrote: > On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: > >> My completely unsolicited advice is that regular expressions shouldn't be > >> very high on the list of things to learn. They are very us

Re: Regular expressions

2015-11-03 Thread rurpy--- via Python-list
On 11/03/2015 12:15 AM, Steven D'Aprano wrote: > On Tue, 3 Nov 2015 03:23 pm, rurpy wrote: > >> Regular expressions should be learned by every programmer or by anyone >> who wants to use computers as a tool. They are a fundamental part of >> computer science and are

Re: Regular expressions

2015-11-03 Thread Robin Koch
Am 03.11.2015 um 05:23 schrieb ru...@yahoo.com: Of course there are people who misuse regexes. /^1?$|^(11+?)\1+$/ There are? 0:-) -- Robin Koch -- https://mail.python.org/mailman/listinfo/python-list

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Grant Edwards
On 2015-11-03, Tim Chase wrote: [re. iterating over lines in a file] > I can't think of more than 1-2 times in my last 10+ years of > Pythoning that I've actually had potential use for the newlines, If you can think of 1-2 times when you've been interating over the lines in a file and wanted to

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 11:39, Ian Kelly wrote: > >> because I have countless loops that look something like > >> > >> with open(...) as f: > >> for line in f: > >> line = line.rstrip('\r\n') > >> process(line) > > > > What would happen if you read a file opened like this without > > iter

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Ian Kelly
On Tue, Nov 3, 2015 at 11:33 AM, Ian Kelly wrote: > On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase > wrote: >> Or even more valuable to me: >> >> with open(..., newline="strip") as f: >> assert all(not line.endswith(("\n", "\r")) for line in f) >> >> because I have countless loops that look som

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Ian Kelly
On Tue, Nov 3, 2015 at 9:56 AM, Tim Chase wrote: > On 2015-11-03 16:35, Peter Otten wrote: >> I wish there were a way to prohibit such files. Maybe a special >> value >> >> with open(..., newline="normalize") f: >> assert all(line.endswith("\n") for line in f) >> >> to ensure that all lines en

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Peter Otten
Tim Chase wrote: > On 2015-11-03 16:35, Peter Otten wrote: >> I wish there were a way to prohibit such files. Maybe a special >> value >> >> with open(..., newline="normalize") f: >> assert all(line.endswith("\n") for line in f) >> >> to ensure that all lines end with "\n"? > > Or even more

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 16:35, Peter Otten wrote: > I wish there were a way to prohibit such files. Maybe a special > value > > with open(..., newline="normalize") f: > assert all(line.endswith("\n") for line in f) > > to ensure that all lines end with "\n"? Or even more valuable to me: with open(

Re: Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Jussi Piitulainen
Peter Otten writes: > Jussi Piitulainen wrote: >> Peter Otten writes: >> >>> If a "line" is defined as a string that ends with a newline >>> >>> def ends_in_asterisk(line): >>> return False >>> >>> would also satisfy the requirement. Lies, damned lies, and specs ;) >> >> Even if a "line" is d

Re: Regular expressions

2015-11-03 Thread Chris Angelico
On Wed, Nov 4, 2015 at 3:10 AM, Seymore4Head wrote: > Yes I knew that -1 represents the end character. It is not a question > of trying to accomplish anything. I was just practicing with regex > and wasn't sure how to express a * since it was one of the > instructions. In that case, it's nothin

Re: Regular expressions

2015-11-03 Thread Seymore4Head
On Tue, 3 Nov 2015 10:34:12 -0500, Joel Goldstick wrote: >On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head >wrote: > >> On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase >> wrote: >> >> >On 2015-11-02 20:09, Seymore4Head wrote: >> >> How do I make a regular expression that returns true if the end of >>

Irregular last line in a text file, was Re: Regular expressions

2015-11-03 Thread Peter Otten
Jussi Piitulainen wrote: > Peter Otten writes: > >> If a "line" is defined as a string that ends with a newline >> >> def ends_in_asterisk(line): >> return False >> >> would also satisfy the requirement. Lies, damned lies, and specs ;) > > Even if a "line" is defined as a string that comes f

Re: Regular expressions

2015-11-03 Thread Joel Goldstick
On Mon, Nov 2, 2015 at 10:17 PM, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > > >On 2015-11-02 20:09, Seymore4Head wrote: > >> How do I make a regular expression that returns true if the end of > >> the line is an asterisk > > > >Why use a regular expression? > >

Re: Regular expressions

2015-11-03 Thread Jussi Piitulainen
Peter Otten writes: > If a "line" is defined as a string that ends with a newline > > def ends_in_asterisk(line): > return False > > would also satisfy the requirement. Lies, damned lies, and specs ;) Even if a "line" is defined as a string that comes from reading something like a file with d

Re: Regular expressions

2015-11-03 Thread Grant Edwards
On 2015-11-03, Tim Chase wrote: > On 2015-11-02 20:09, Seymore4Head wrote: >> How do I make a regular expression that returns true if the end of >> the line is an asterisk > > Why use a regular expression? > > if line[-1] == '*': Why use a negative index and then a compare? if line.endswit

Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-02 22:17, Seymore4Head wrote: > On Mon, 2 Nov 2015 20:42:37 -0600, Tim Chase > wrote: > > >On 2015-11-02 20:09, Seymore4Head wrote: > >> How do I make a regular expression that returns true if the end > >> of the line is an asterisk > > > >Why use a regular expression? > > > Because th

Re: Regular expressions

2015-11-03 Thread Peter Otten
Tim Chase wrote: > On 2015-11-03 10:25, Peter Otten wrote: >> >>> How do I make a regular expression that returns true if the end >> >>> of the line is an asterisk >> >> >> >> Why use a regular expression? >> >> >> >> if line[-1] == '*': >> >> yep(line) >> >> else: >> >> nope(line) >

Re: Regular expressions

2015-11-03 Thread Denis McMahon
k >>Why use a regular expression? > Because that is the part of Python I am trying to learn at the moment. The most important thing to learn about regular expressions is when to use them and when not to use them. Returning true if the last character in a string is an asterisk is almost ce

Re: Regular expressions

2015-11-03 Thread Tim Chase
On 2015-11-03 10:25, Peter Otten wrote: > >>> How do I make a regular expression that returns true if the end > >>> of the line is an asterisk > >> > >> Why use a regular expression? > >> > >> if line[-1] == '*': > >> yep(line) > >> else: > >> nope(line) > > Incidentally the code exa

Re: Regular expressions

2015-11-03 Thread Peter Otten
gt; >> if line[-1] == '*': >> yep(line) >> else: >> nope(line) > > Indeed, sometimes Jamie Zawinski's is often quite appropriate: > > Some people, when confronted with a problem, think "I know, I'll use > regular expressions.

Re: Regular expressions

2015-11-03 Thread Nick Sarbicki
On Tue, Nov 3, 2015 at 7:15 AM, Steven D'Aprano wrote: > On Tue, 3 Nov 2015 03:23 pm, ru...@yahoo.com wrote: > > > Regular expressions should be learned by every programmer or by anyone > > who wants to use computers as a tool. They are a fundamental part of > > com

Re: Regular expressions

2015-11-02 Thread Steven D'Aprano
On Tue, 3 Nov 2015 03:23 pm, ru...@yahoo.com wrote: > Regular expressions should be learned by every programmer or by anyone > who wants to use computers as a tool.  They are a fundamental part of > computer science and are used in all sorts of matching and searching > from compilers

Re: Regular expressions

2015-11-02 Thread Michael Torrie
On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: >> My completely unsolicited advice is that regular expressions shouldn't be >> very high on the list of things to learn. They are very useful, and very >> tricky and prone many problems that can and should be learned

Re: Regular expressions

2015-11-02 Thread Michael Torrie
On 11/02/2015 09:23 PM, rurpy--- via Python-list wrote: > On 11/02/2015 08:51 PM, Michael Torrie wrote: >> [...] >> Indeed, sometimes Jamie Zawinski's is often quite appropriate: >> >> Some people, when confronted with a problem, think "I know, I'll

Re: Regular expressions

2015-11-02 Thread rurpy--- via Python-list
>nope(line) > > > > > >-tkc > > > > > > > > Because that is the part of Python I am trying to learn at the moment. > > Thanks > > -- > > https://mail.python.org/mailman/listinfo/python-list > > > > My completely unsolicited advi

  1   2   3   4   5   6   7   8   >