Re: [Tutor] Regex Question

2013-09-30 Thread Mark Lawrence
On 30/09/2013 21:29, Leena Gupta wrote: Hello, I have a TSV file that has the city,state,country information in this format: Name Display name Code San Jose SJC SJC - SJ (POP), CA (US) San Francisco SFOSFO - SF, CA (US) I need

Re: [Tutor] Regex Question

2013-09-30 Thread Dave Angel
On 30/9/2013 16:29, Leena Gupta wrote: > Hello, > > I have a TSV file that has the city,state,country information in this > format: > Name Display name Code > San Jose SJC SJC - SJ (POP), CA (US) > San Francisco SFOSFO - SF, CA (

[Tutor] Regex Question

2013-09-30 Thread Leena Gupta
Hello, I have a TSV file that has the city,state,country information in this format: Name Display name Code San Jose SJC SJC - SJ (POP), CA (US) San Francisco SFOSFO - SF, CA (US) I need to extract the state and country for each

Re: [Tutor] regex question

2012-04-08 Thread kaifeng jin
I think you can do this: a=[] b=redata.split('::') for e in b: if e.find('@') != -1: a.append(e.split('@')[1]) list a includes all the domain 在 2012年4月9日 上午5:26,Wayne Werner 写道: > On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote: > > hi all, >> I'm trying to extract the domain in the foll

Re: [Tutor] regex question

2012-04-08 Thread Wayne Werner
On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote: hi all, I'm trying to extract the domain in the following string. Why doesn't my pattern (patt) work: >>> redata 'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul 31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 2

Re: [Tutor] regex question

2012-04-05 Thread Peter Otten
Khalid Al-Ghamdi wrote: > I'm trying to extract the domain in the following string. Why doesn't my > pattern (patt) work: > redata > 'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul > 31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37 > 1987::ttw..

[Tutor] regex question

2012-04-05 Thread Khalid Al-Ghamdi
hi all, I'm trying to extract the domain in the following string. Why doesn't my pattern (patt) work: >>> redata 'Tue Jan 14 00:43:21 2020::eax...@gstwyysnbd.gov::1578951801-6-10 Sat Jul 31 15:17:39 1993::rz...@wgxvhx.com::744121059-5-6 Mon Sep 21 20:22:37 1987::ttw...@rpybrct.edu::559243357-6-7

Re: [Tutor] Regex question

2011-04-03 Thread Peter Otten
Hugo Arts wrote: > 2011/4/3 "Andrés Chandía" : >> >> >> I continue working with RegExp, but I have reached a point for wich I >> can't find documentation, maybe there is no possible way to do it, any >> way I throw the question: >> >> This is my code: >> >> contents = re.sub(r'Á', >> "A", contents

Re: [Tutor] Regex question

2011-04-03 Thread Hugo Arts
2011/4/3 "Andrés Chandía" : > > > I continue working with RegExp, but I have reached a point for wich I can't > find > documentation, maybe there is no possible way to do it, any way I throw the > question: > > This is my code: > >     contents = re.sub(r'Á', > "A", contents) >     contents = re.

Re: [Tutor] Regex question

2011-04-03 Thread Andrés Chandía
I continue working with RegExp, but I have reached a point for wich I can't find documentation, maybe there is no possible way to do it, any way I throw the question: This is my code:     contents = re.sub(r'Á', "A", contents)     contents = re.sub(r'á', "a", contents)     contents = re.sub(r'

Re: [Tutor] Regex question

2011-03-30 Thread Andrés Chandía
Thanks Steve, your are, from now on, my guru this is the final version, the good one! contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', r"\2'" ,contents) On Wed, March 30, 2011 17:27, Steve Willoughby wrote: On 30-Mar-11 08:21, "Andrés Chandía" wrote: > > > Thanks Kushal and Steve. > I think it w

Re: [Tutor] Regex question

2011-03-30 Thread Steve Willoughby
On 30-Mar-11 08:21, "Andrés Chandía" wrote: Thanks Kushal and Steve. I think it works,a I say "I think" because at the results I got a strange character instead of the letter that should appear this is my regexp: contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', '\2\'' ,contents) Remember that \2 i

Re: [Tutor] Regex question

2011-03-30 Thread Andrés Chandía
Thanks Kushal and Steve. I think it works,a I say "I think" because at the results I got a strange character instead of the letter that should appear this is my regexp: contents = re.sub(r'(|)(l|L|n|N|t|T)(|)', '\2\'' ,contents) this is my input file content: lomo  nomo  tomo  Lomo  Nomo 

Re: [Tutor] Regex question

2011-03-30 Thread Steve Willoughby
On 29-Mar-11 23:55, Alan Gauld wrote: ""Andrés Chandía"" wrote in perl there is a way to reference previous registers, $text =~ s/(l|L|n|N)<\/u>/$1e/g; I'm looking for the way to do it in python If you're using just a straight call to re.sub(), it works like this: text = re.sub(r

[Tutor] Regex question

2011-03-30 Thread Alan Gauld
""Andrés Chandía"" wrote I'm new to this list, so hello everybody!. Hi, welcome to the list. Please do not use reply to start a new thread it confuses threaded readers and may mean you message will not be seen. Also please supply a meaningful subject (as above) so we can decide if it looks

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 14:58, Steven D'Aprano wrote: > Dave Angel wrote: > >> One hazard is if the string the user inputs has any regex special >> characters in it.  If it's anything but letters and digits you probably want >> to escape it before combining it with your \\b strings. > > It is best

Re: [Tutor] regex question

2011-01-04 Thread Steven D'Aprano
Dave Angel wrote: One hazard is if the string the user inputs has any regex special characters in it. If it's anything but letters and digits you probably want to escape it before combining it with your \\b strings. It is best to escape any user-input before passing it to regex regardless.

Re: [Tutor] regex question

2011-01-04 Thread Dave Angel
On 01/-10/-28163 02:59 PM, Richard D. Moores wrote: On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote: On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually searching RTF files, not TXT files. I want to modify this script t

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores wrote: > On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: >> Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually >> searching RTF files, not TXT files. >> >> I want to modify this script to handle searching on a word. So what, >> f

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 10:41, Richard D. Moores wrote: > Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually > searching RTF files, not TXT files. > > I want to modify this script to handle searching on a word. So what, > for example, should line 71 be? OK, I think I've got it. in pl

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually searching RTF files, not TXT files. I want to modify this script to handle searching on a word. So what, for example, should line 71 be? Dick ___ Tutor maillist - Tutor@python.org To unsu

Re: [Tutor] regex question

2011-01-04 Thread Brett Ritter
On Tue, Jan 4, 2011 at 11:07 AM, Richard D. Moores wrote: > A file has these 2 lines: > > alksdhjf ksjhdf kjshf dex akjdhf jkdshf jsdhf > alkdshf jkashd flkjdsf index alkdjshf alkdjshf > > And I want the only line that contains the word "dex" Ah! Then you want a slightly different Regex pattern.

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 09:31, Brett Ritter wrote: > On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote: >> regex = ".*" + search + ".*" >> p = re.compile(regex, re.I) > > Just having "search" as your regex is fine (it will search for the > pattern _in_ the string, no need to specify the ot

Re: [Tutor] regex question

2011-01-04 Thread Brett Ritter
On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores wrote: > regex = ".*" + search + ".*" > p = re.compile(regex, re.I) > > in finding lines in a text file that contain search, a string entered > at a prompt. That's an inefficient regex (though the compiler may be smart enough to prune the unneede

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 07:55, Wayne Werner wrote: > On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores > You could use (2.6+ I think): > word = raw_input('Enter word to search for: ') > with open('somefile.txt') as f: >    for line in f: >        if word in line: >             print line I think

Re: [Tutor] regex question

2011-01-04 Thread Wayne Werner
On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores wrote: > I use > > regex = ".*" + search + ".*" > p = re.compile(regex, re.I) > > in finding lines in a text file that contain search, a string entered > at a prompt. > > What regex do I use to find lines in a text file that contain search, > where

[Tutor] regex question

2011-01-04 Thread Richard D. Moores
I use regex = ".*" + search + ".*" p = re.compile(regex, re.I) in finding lines in a text file that contain search, a string entered at a prompt. What regex do I use to find lines in a text file that contain search, where search is a word entered at a prompt? Thanks, Dick Moores __