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
On Fri, Sep 20, 2019 at 1:07 AM Pradeep Patra wrote: > > 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

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 please help? I

Re: Regular expressions, help?

2012-04-19 Thread Andy
If you plan on doing more work with regular expressions in the future and you have access to a Windows machine you may want to consider picking up a copy of RegxBuddy. I don't have any affiliation with the makers but I have been using the software for a few years and it has saved me a lot of fru

Re: Regular expressions, help?

2012-04-19 Thread Chris Angelico
On Fri, Apr 20, 2012 at 1:07 AM, Sania wrote: > Azrazer what you suggested works but I need to make sure that it > catches numbers like 6,370 as well as 637. And I tried tweaking the > regex around from the one you said in your reply but It didn't work > (probably would have if I was more adept).

Re: Regular expressions, help?

2012-04-19 Thread Sania
On Apr 19, 9:52 am, Jon Clements wrote: > On Thursday, 19 April 2012 07:11:54 UTC+1, Sania  wrote: > > Hi, > > So I am trying to get the number of casualties in a text. After 'death > > toll' in the text the number I need is presented as you can see from > > the variable called text. Here is my co

Re: Regular expressions, help?

2012-04-19 Thread Jon Clements
On Thursday, 19 April 2012 07:11:54 UTC+1, Sania wrote: > Hi, > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think i

Re: Regular expressions, help?

2012-04-19 Thread Jussi Piitulainen
Sania writes: > On Apr 19, 2:48 am, Jussi Piitulainen > wrote: > > Sania writes: > > > So I am trying to get the number of casualties in a text. After 'death > > > toll' in the text the number I need is presented as you can see from > > > the variable called text. Here is my code > > > I'm pretty

Re: Regular expressions, help?

2012-04-19 Thread azrazer
Le 19/04/2012 14:02, Sania a écrit : On Apr 19, 2:48 am, Jussi Piitulainen [...] text="accounts put the death toll at 637 and those missing at 653 , but the total number is likely to be much bigger" dead=re.match(r".*death toll.*(\d[,\d\.]*)", text) deadnum=dead.group(1)

Re: Regular expressions, help?

2012-04-19 Thread Chris Angelico
On Thu, Apr 19, 2012 at 10:02 PM, Sania wrote: > So now my regex is > >    dead=re.match(r".*death toll.{0,20}(\d[,\d\.]*)", text) > > But I only find 7 not 657. How is it that the group is only matching > the last digit? The whole thing is parenthesis not just the last > part. ? Your problem is

Re: Regular expressions, help?

2012-04-19 Thread Sania
On Apr 19, 2:48 am, Jussi Piitulainen wrote: > Sania writes: > > So I am trying to get the number of casualties in a text. After 'death > > toll' in the text the number I need is presented as you can see from > > the variable called text. Here is my code > > I'm pretty sure my regex is correct, I

Re: Regular expressions, help?

2012-04-18 Thread Jussi Piitulainen
Sania writes: > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. > I am

Re: Regular expressions, help?

2012-04-18 Thread Cameron Simpson
On 18Apr2012 23:11, Sania wrote: | So I am trying to get the number of casualties in a text. After 'death | toll' in the text the number I need is presented as you can see from | the variable called text. Here is my code | I'm pretty sure my regex is correct, I think it's the group part | that's t

Re: Regular expressions, help?

2012-04-18 Thread Peter Otten
Sania wrote: > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. No. A r

Re: Regular expressions, help?

2012-04-18 Thread Peter Otten
Sania wrote: > Hi, > So I am trying to get the number of casualties in a text. After 'death > toll' in the text the number I need is presented as you can see from > the variable called text. Here is my code > I'm pretty sure my regex is correct, I think it's the group part > that's the problem. N

Regular expressions, help?

2012-04-18 Thread Sania
Hi, So I am trying to get the number of casualties in a text. After 'death toll' in the text the number I need is presented as you can see from the variable called text. Here is my code I'm pretty sure my regex is correct, I think it's the group part that's the problem. I am using nltk by python. G