Re: Question about regular expression

2015-10-02 Thread Denis McMahon
On Wed, 30 Sep 2015 23:30:47 +, Denis McMahon wrote: > On Wed, 30 Sep 2015 11:34:04 -0700, massi_srb wrote: > >> firstly the description of my problem. I have a string in the following >> form: . > > The way I solved this was to: > > 1) replace all the punctuation in the string with spa

Re: Question about regular expression

2015-10-01 Thread gal kauffman
On Oct 2, 2015 12:35 AM, "Denis McMahon" wrote: > > On Thu, 01 Oct 2015 01:48:03 -0700, gal kauffman wrote: > > > items = s.replace(' (', '(').replace(', ',',').split() > > > > items_dict = dict() > > for item in items: > > if '(' not in item: > > item += '(0,0)' > > if ',' not in

Re: Question about regular expression

2015-10-01 Thread Denis McMahon
On Thu, 01 Oct 2015 15:53:38 +, Rob Gaddi wrote: > There's a quote for this. 'Some people, when confronted with a problem, > think “I know, I'll use regular expressions.” Now they have two > problems.' I actually used 2 regexes: wordpatt = re.compile('[a-zA-Z]+') numpatt = re.compile('[0-

Re: Question about regular expression

2015-10-01 Thread Denis McMahon
On Thu, 01 Oct 2015 01:48:03 -0700, gal kauffman wrote: > items = s.replace(' (', '(').replace(', ',',').split() > > items_dict = dict() > for item in items: > if '(' not in item: > item += '(0,0)' > if ',' not in item: > item = item.replace(')', ',0)') > > name, raw_

Re: Question about regular expression

2015-10-01 Thread Rob Gaddi
On Wed, 30 Sep 2015 11:34:04 -0700, massi_srb wrote: > Hi everyone, > > firstly the description of my problem. I have a string in the following > form: > > s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." > > that is a string made up of groups in the form 'name' (letters only) > plus possib

Re: Question about regular expression

2015-10-01 Thread gal kauffman
My example will give false positive if there is a space before a comma. Or anything else by the conventions in the original string. I tried to keep it as simple as I could. If you want to catch a wider range of values you can use *simple* regular expression to catch as much spaces as you want. On O

Re: Question about regular expression

2015-10-01 Thread Tim Chase
On 2015-10-01 01:48, gal kauffman wrote: > items = s.replace(' (', '(').replace(', ',',').split() s = "name1 (1)" Your suggestion doesn't catch cases where more than one space can occur before the paren. -tkc -- https://mail.python.org/mailman/listinfo/python-list

Re: Question about regular expression

2015-10-01 Thread gal kauffman
items = s.replace(' (', '(').replace(', ',',').split() items_dict = dict() for item in items: if '(' not in item: item += '(0,0)' if ',' not in item: item = item.replace(')', ',0)') name, raw_data = item.split('(') data_tuple = tuple((int(v) for v in raw_data.repla

Re: Question about regular expression

2015-09-30 Thread Emile van Sebille
On 9/30/2015 12:20 PM, Tim Chase wrote: On 2015-09-30 11:34, massi_...@msn.com wrote: I guess this problem can be tackled with regular expressions, b ... However, if you *want* to do it with regular expressions, you can. It's ugly and might be fragile, but ##

Re: Question about regular expression

2015-09-30 Thread Denis McMahon
On Wed, 30 Sep 2015 11:34:04 -0700, massi_srb wrote: > firstly the description of my problem. I have a string in the following > form: . The way I solved this was to: 1) replace all the punctuation in the string with spaces 2) split the string on space 3) process each thing in the list to

Re: Question about regular expression

2015-09-30 Thread Tim Chase
On 2015-09-30 11:34, massi_...@msn.com wrote: > firstly the description of my problem. I have a string in the > following form: > > s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." > > that is a string made up of groups in the form 'name' (letters > only) plus possibly a tuple containing 1 or

Re: Question about regular expression

2015-09-30 Thread Joel Goldstick
On Wed, Sep 30, 2015 at 2:50 PM, Emile van Sebille wrote: > On 9/30/2015 11:34 AM, massi_...@msn.com wrote: > >> Hi everyone, >> >> firstly the description of my problem. I have a string in the following >> form: >> >> s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." >> >> that is a string ma

Re: Question about regular expression

2015-09-30 Thread Emile van Sebille
On 9/30/2015 11:34 AM, massi_...@msn.com wrote: Hi everyone, firstly the description of my problem. I have a string in the following form: s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing

Question about regular expression

2015-09-30 Thread massi_srb
Hi everyone, firstly the description of my problem. I have a string in the following form: s = "name1 name2(1) name3 name4 (1, 4) name5(2) ..." that is a string made up of groups in the form 'name' (letters only) plus possibly a tuple containing 1 or 2 integer values. Blanks can be placed betwe