Re: [Tutor] Help with re in Python 3

2011-11-05 Thread Andreas Perstinger
On 2011-11-04 20:59, Albert-Jan Roskam wrote: It seems that you are not opening the file properly. You could do f = file('///Users/joebatt/Desktop/python3.txt','r') or: withfile('///Users/joebatt/Desktop/python3.txt','r') as f: OP is using Python 3, where file is removed. Thus, you have to use

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Joel Goldstick
On Fri, Nov 4, 2011 at 3:42 PM, Joe Batt joeb...@hotmail.co.uk wrote: Hi all, Still trying with Python and programming in general…. I am trying to get a grip with re. I am writing a program to open a text file and scan it for exactly 3 uppercase letters in a row followed by a lowercase

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Albert-Jan Roskam
? ~~ From: Joe Batt joeb...@hotmail.co.uk To: tutor@python.org Sent: Friday, November 4, 2011 8:42 PM Subject: [Tutor] Help with re in Python 3 Hi all, Still trying with Python and programming in general

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Prasad, Ramit
m = re.search([A-Z]{3}[a-z][A-Z]{3}, line) That is the expression I would suggest, except it is still more efficient to use a compiled regular expression like the original version. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX

Re: [Tutor] Help with re in Python 3

2011-11-04 Thread Steven D'Aprano
Prasad, Ramit wrote: m = re.search([A-Z]{3}[a-z][A-Z]{3}, line) That is the expression I would suggest, except it is still more efficient to use a compiled regular expression like the original version. Not necessarily. The Python regex module caches recently used regex strings, avoiding

Re: [Tutor] help with re module and parsing data

2011-03-07 Thread Kushal Kumaran
On Mon, Mar 7, 2011 at 1:24 PM, vineeth vineethrak...@gmail.com wrote: Hello all I am doing some analysis on my trace file. I am finding the lines Recvd-Content and Published-Content. I am able to find those lines but the re module as predicted just gives the word that is being searched. But I

Re: [Tutor] help with re module and parsing data

2011-03-07 Thread wesley chun
import re file = open('file.txt','r') file2 = open('newfile.txt','w') LineFile = ' ' for line in file:    LineFile += line StripRcvdCnt = re.compile('(P\w+\S\Content|Re\w+\S\Content)') FindRcvdCnt = re.findall(StripRcvdCnt, LineFile) for SrcStr in FindRcvdCnt:    file2.write(SrcStr)

Re: [Tutor] help with re module and parsing data

2011-03-07 Thread Steven D'Aprano
On Mon, 7 Mar 2011 06:54:30 pm vineeth wrote: Hello all I am doing some analysis on my trace file. I am finding the lines Recvd-Content and Published-Content. I am able to find those lines but the re module as predicted just gives the word that is being searched. But I require the entire line

Re: [Tutor] Help on RE

2011-01-23 Thread Japhy Bartlett
it's a bug in your regex - you want something like -?\d+ - japhy On Sat, Jan 22, 2011 at 7:38 PM, tee chwee liong tc...@hotmail.com wrote: hi, i have a set of data and using re to extract it into array. however i only get positive value, how to extract the whole value including the -ve sign?

Re: [Tutor] Help on RE

2011-01-23 Thread Albert-Jan Roskam
health, what have the Romans ever done for us? ~~ From: Steven D'Aprano st...@pearwood.info To: tutor@python.org Sent: Sun, January 23, 2011 4:10:35 AM Subject: Re: [Tutor] Help on RE tee chwee

Re: [Tutor] Help on RE

2011-01-22 Thread tee chwee liong
thanks it works!! :) Date: Sat, 22 Jan 2011 19:51:35 -0500 Subject: Re: [Tutor] Help on RE From: ja...@pearachute.com To: tc...@hotmail.com CC: tutor@python.org it's a bug in your regex - you want something like -?\d+ - japhy On Sat, Jan 22, 2011 at 7:38 PM, tee chwee liong tc

Re: [Tutor] Help on RE

2011-01-22 Thread tee chwee liong
thanks for making me understand more on re. re is a confusing topic as i'm starting on python. Date: Sat, 22 Jan 2011 16:55:37 -0800 From: st...@alchemy.com To: tc...@hotmail.com CC: tutor@python.org Subject: Re: [Tutor] Help on RE On Sun, Jan 23, 2011 at 12:38:10AM +, tee chwee

Re: [Tutor] Help on RE

2011-01-22 Thread Steve Willoughby
On Sun, Jan 23, 2011 at 12:38:10AM +, tee chwee liong wrote: i have a set of data and using re to extract it into array. however i only get positive value, how to extract the whole value including the -ve sign? numbers = re.findall(\d+, line) The \d matches a digit character. \d+

Re: [Tutor] Help on RE

2011-01-22 Thread Steven D'Aprano
tee chwee liong wrote: thanks for making me understand more on re. re is a confusing topic as i'm starting on python. I quote the great Jamie Zawinski, a world-class programmer and hacker: Some people, when confronted with a problem, think 'I know, I'll use regular expressions. Now

Re: [Tutor] Help on RE

2011-01-22 Thread tee chwee liong
elegant. :) simple yet elegant. Date: Sun, 23 Jan 2011 14:10:35 +1100 From: st...@pearwood.info To: tutor@python.org Subject: Re: [Tutor] Help on RE tee chwee liong wrote: thanks for making me understand more on re. re is a confusing topic as i'm starting on python. I quote