[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

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 (US)

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

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

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 wa...@waynewerner.com写道: On Fri, 6 Apr 2012, Khalid Al-Ghamdi wrote: hi all, I'm trying to extract the

Re: [Tutor] regex question

2012-04-06 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

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-04-03 Thread Hugo Arts
2011/4/3 Andrés Chandía and...@chandia.net: 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: [Tutor] Regex question

2011-04-03 Thread Peter Otten
Hugo Arts wrote: 2011/4/3 Andrés Chandía and...@chandia.net: 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)

[Tutor] Regex question

2011-03-30 Thread Alan Gauld
Andrés Chandía and...@chandia.net 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

Re: [Tutor] Regex question

2011-03-30 Thread Steve Willoughby
On 29-Mar-11 23:55, Alan Gauld wrote: Andrés Chandía and...@chandia.net wrote in perl there is a way to reference previous registers, $text =~ s/u(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:

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'(u|span style=text-decoration: underline;)(l|L|n|N|t|T)(/span|/u)', '\2\'' ,contents) this is my input

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'(u|span style=text-decoration:

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'(u|span style=text-decoration: underline;)(l|L|n|N|t|T)(/span|/u)', r\2' ,contents) On Wed, March 30, 2011 17:27, Steve Willoughby wrote: On 30-Mar-11 08:21, Andrés Chandía wrote:

[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

Re: [Tutor] regex question

2011-01-04 Thread Wayne Werner
On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores rdmoo...@gmail.comwrote: 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,

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 07:55, Wayne Werner waynejwer...@gmail.com wrote: On Tue, Jan 4, 2011 at 9:37 AM, Richard D. Moores rdmoo...@gmail.com 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

Re: [Tutor] regex question

2011-01-04 Thread Brett Ritter
On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores rdmoo...@gmail.com 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

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 09:31, Brett Ritter swift...@swiftone.org wrote: On Tue, Jan 4, 2011 at 10:37 AM, Richard D. Moores rdmoo...@gmail.com 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,

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 10:41, Richard D. Moores rdmoo...@gmail.com 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

Re: [Tutor] regex question

2011-01-04 Thread Richard D. Moores
On Tue, Jan 4, 2011 at 11:57, Richard D. Moores rdmoo...@gmail.com wrote: On Tue, Jan 4, 2011 at 10:41, Richard D. Moores rdmoo...@gmail.com 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

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. Mooresrdmoo...@gmail.com wrote: On Tue, Jan 4, 2011 at 10:41, Richard D. Mooresrdmoo...@gmail.com wrote: Please see http://tutoree7.pastebin.com/z9YeSYRw . I'm actually searching RTF files, not TXT

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 Richard D. Moores
On Tue, Jan 4, 2011 at 14:58, Steven D'Aprano st...@pearwood.info 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.