Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Mon, Oct 29, 2018 at 05:16:11PM +, MRAB wrote: > > Logically it should not because > > > > >s'::15>>$ > > > > does not match > > > > ::\d*>>$ > > > > but I am not sure how to tell it that :-) > > > For something like that, I'd use parsing by recursive descent. > > It might be

Re: regular expression problem

2018-10-29 Thread MRAB
On 2018-10-29 08:02, Karsten Hilbert wrote: On Sun, Oct 28, 2018 at 11:14:15PM +, MRAB wrote: > - lines can contain several placeholders > > - placeholders start and end with '$' > > - placeholders are parsed in three passes > > - the pass in which a placeholder is parsed is denoted by t

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 11:57:48PM +0100, Brian Oney wrote: > On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote: > > [^<:] > > Would a simple regex work? This brought about the solution. However, not this way: > >>> import re > >>> t = '$$' > >>> re.findall('[^<>:$]+', t) > ['name', 'op

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
> Right, I am not trying to do that. I was, however, worried > that I need to make the expression not "trip over" fragments > of what might seem to constitute part of another placeholder. > > $<$::15>>$ > > Pass 1 might fill in to: > > $>$ > > and I was worried to make sure

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Mon, Oct 29, 2018 at 12:10:04AM +0100, Thomas Jollans wrote: > On 28/10/2018 22:04, Karsten Hilbert wrote: > > - options needs to be able to contain nearly anything, except '::' > > Including > and $ ? Unfortunately, it might. Even if I assume that earlier passes are "inside", and thusly "fil

Re: regular expression problem

2018-10-29 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 11:14:15PM +, MRAB wrote: > > - lines can contain several placeholders > > > > - placeholders start and end with '$' > > > > - placeholders are parsed in three passes > > > > - the pass in which a placeholder is parsed is denoted by the number of '<' > > and '>' nex

Re: regular expression problem

2018-10-28 Thread Thomas Jollans
On 28/10/2018 22:04, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' Including > and $ ? -- https://mail.python.org/mailman/listinfo/python-list

Re: regular expression problem

2018-10-28 Thread Thomas Jollans
On 28/10/2018 22:04, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' > > Is that sufficiently defined and helpful to design the regular expression ? so options isn't '.*', but more like '(:?[^:]+)*' (Figuring out what additional restriction this imposes

Re: regular expression problem

2018-10-28 Thread MRAB
On 2018-10-28 21:04, Karsten Hilbert wrote: On Sun, Oct 28, 2018 at 09:43:27PM +0100, Karsten Hilbert wrote: Let my try to explain the expression I am actually after (assuming .compile with re.VERBOSE): rx_works = ' \$< # start of match is literal '$<' anywhere

Re: regular expression problem

2018-10-28 Thread Brian Oney via Python-list
On Sun, 2018-10-28 at 22:04 +0100, Karsten Hilbert wrote: > [^<:] Would a simple regex work? I mean: ~$ python Python 2.7.13 (default, Sep 26 2018, 18:42:22)  [GCC 6.3.0 20170516] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import re >>> t = '$$' >>> re.f

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 10:04:39PM +0100, Karsten Hilbert wrote: > - options needs to be able to contain nearly anything, except '::' This seems to contradict the "nesting" requirement, but the nesting restriction "earlier parsing passes go inside" makes it possible. Karsten -- GPG 40BE 5B0E C

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
On Sun, Oct 28, 2018 at 09:43:27PM +0100, Karsten Hilbert wrote: > Let my try to explain the expression I am actually after > (assuming .compile with re.VERBOSE): > > rx_works = ' > \$< # start of match is literal '$<' > anywhere inside string > [^<:]+?::

Re: regular expression problem

2018-10-28 Thread Karsten Hilbert
Now that MRAB has shown me the follies of my ways I would like to learn how to properly write the regular expression I need. This part: > rx_works = '\$<[^<:]+?::.*?::\d*?>\$|\$<[^<:]+?::.*?::\d+-\d+>\$' > # it fails if switched around: > rx_fails = '\$<[^<:]+?::.*?::\d+-\d+>\$|\$<[^<:]+?::.*?::\

Re: regular expression problem

2018-10-28 Thread MRAB
On 2018-10-28 18:51, Karsten Hilbert wrote: Dear list members, I cannot figure out why my regular expression does not work as I expect it to: #--- #!/usr/bin/python from __future__ import print_function import re as regex rx_works = '\$<[^<:]+?::.*?::\d*?>\$|\$<[^<:]+?

Re: Regular expression problem

2013-03-11 Thread Terry Reedy
On 3/11/2013 2:30 PM, Serhiy Storchaka wrote: On 11.03.13 04:06, Terry Reedy wrote: On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python s

Re: Regular expression problem

2013-03-11 Thread Serhiy Storchaka
On 11.03.13 04:06, Terry Reedy wrote: On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all lan

Re: Regular expression problem

2013-03-11 Thread rusi
On Mar 11, 2:28 pm, jmfauth wrote: > On 11 mar, 03:06, Terry Reedy wrote: > > > > > ... > > By teaching 'speed before correctness", this site promotes bad > > programming habits and thinking (and the use of low-level but faster > > languages). > > ... > > This is exactly what "your" flexible stri

Re: Regular expression problem

2013-03-11 Thread Mark Lawrence
On 11/03/2013 09:28, jmfauth wrote: On 11 mar, 03:06, Terry Reedy wrote: ... By teaching 'speed before correctness", this site promotes bad programming habits and thinking (and the use of low-level but faster languages). ... This is exactly what "your" flexible string representation does!

Re: Regular expression problem

2013-03-11 Thread jmfauth
On 11 mar, 03:06, Terry Reedy wrote: > > ... > By teaching 'speed before correctness", this site promotes bad > programming habits and thinking (and the use of low-level but faster > languages). > ... This is exactly what "your" flexible string representation does! And away from technical aspe

Re: Regular expression problem

2013-03-10 Thread Terry Reedy
On 3/10/2013 1:42 PM, mukesh tiwari wrote: Hello all I am trying to solve this problem[1] [1] http://www.spoj.com/problems/MAIN12C/ As I remember, and as it still appears, this site severely penalizes Python solvers by using the same time limit for all languages. Thus, a 'slow' python program

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 5:48 AM, mukesh tiwari wrote: > Hi Chris > Thank you! Now I am getting wrong answer so at least program is faster then > previous one and I am looking for wrong answer reason. Thanks again! Excellent! Have fun. Incidentally, regular expressions aren't the only way to sol

Re: Regular expression problem

2013-03-10 Thread mukesh tiwari
Hi Chris Thank you! Now I am getting wrong answer so at least program is faster then previous one and I am looking for wrong answer reason. Thanks again! import re if __name__ == "__main__": n = int ( raw_input() ) c = 1 while c <= n : email = filter ( lambda x : x != None ,

Re: Regular expression problem

2013-03-10 Thread mukesh tiwari
Hi Chris On the problem page, it is 3 second. > What is the time limit? I just tried it (Python 2.6 under Windows) and > > it finished in a humanly-immeasurable amount of time. Are you sure > > that STDIN (eg raw_input()) is where your test data is coming from? Yes, on SPOJ we read data from

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:59 AM, Chris Angelico wrote: > On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari > wrote: >> I am trying to solve this problem[1] using regular expression. I wrote this >> code but I am getting time limit exceed. Could some one please tell me how >> to make this code run

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari wrote: > I am trying to solve this problem[1] using regular expression. I wrote this > code but I am getting time limit exceed. Could some one please tell me how to > make this code run faster. What is the time limit? I just tried it (Python 2.6 un

Re: Regular Expression problem

2009-09-08 Thread Steven D'Aprano
On Tue, 08 Sep 2009 09:21:35 +, §äŽmŠÛ€vªº...@€ù€Ñ wrote: > I have the following source code > > > import re > d = 'RTCB\r\nsignature:\xf1\x11 > \xde\x10\xfe\x0f\x9c\x10\xf6\xc9_\x10\xf3\xeb<\x10\xf2Zt\x10\xef\xd2\x91 \x10\xe6\xe7\xfb\x10\xe5p\x99\x10\x

Re: Regular Expression problem

2009-09-08 Thread Vlastimil Brom
2009/9/8 找尋自己的一片天 : > I have the following source code > > > import re > d = 'RTCB\r\nsignature:\xf1\x11 > \xde\x10\xfe\x0f\x9c\x10\xf6\xc9_\x10\xf3\xeb<\x10\xf2Zt\x10\xef\xd2\x91\x10\xe6\xe7\xfb\x10\xe5p\x99\x10\xe2\x1e\xdf\x10\xdb\x0e\x9f\x10\xd8p\x06\x10\

Re: Regular expression problem

2008-06-23 Thread MRAB
On Jun 22, 10:13 pm, abranches <[EMAIL PROTECTED]> wrote: > Hello everyone. > > I'm having a problem when extracting data from HTML with regular > expressions. > This is the source code: > > You are ready in the next style="display: inline;">12 span>M 48S > > And I need to get the remaining time. U

Re: regular expression problem

2007-04-30 Thread Gabriel Genellina
En Mon, 30 Apr 2007 19:16:58 -0300, John Davis <[EMAIL PROTECTED]> escribió: > Hi all, > I have a large logged string "str". I would like to strip down "str" so > that > it contains only the lines that have "ERROR" in them. Could somebody > give me > and indication of how to do this? Forget

RE: Regular Expression problem

2006-07-16 Thread Paul McGuire
> > Less is more: > > pat = re.compile(r'href="([^"]+)') > pat.search(your_link) > > Be sure to also catch: And it's not certain whether the OP is interested in tags like: -- Paul -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression problem

2006-07-16 Thread Barry
On 13 Jul 2006 23:12:05 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote: Pyparsing is also good for recognizing basic HTML tags and theirattributes, regardless of the order of the attributes.-- PaultestText = """sldkjflsa;fajhere it would be 'mystylesheet.css'. I used the following regex to getthis v

Re: Regular Expression problem

2006-07-13 Thread Paul McGuire
Pyparsing is also good for recognizing basic HTML tags and their attributes, regardless of the order of the attributes. -- Paul testText = """sldkjflsa;faj here it would be 'mystylesheet.css'. I used the following regex to get this value(I dont know if it I thought I was doing fine until I go

Re: Regular Expression problem

2006-07-13 Thread Ant
> So What should I do to get the exact value(here the value after > 'href=') in any case even if the > > tags are like these? >> > > > -OR- > > -OR- > The following should do it: expr = r'http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression problem

2006-07-13 Thread Justin Azoff
Justin Azoff wrote: > >>> from BeautifulSoup import BeautifulSoup > >>> html='' > >>> page=BeautifulSoup(html) > >>> page.link.get('href') > 'mystylesheet.css' On second thought, you will probably want something like >>> [link.get('href') for link in page.fetch('link',{'type':'text/css'})] ['myst

Re: Regular Expression problem

2006-07-13 Thread Justin Azoff
John Blogger wrote: > That I want a particular tag value of one of my HTML files. > > ie: I want only the value after 'href=' in the tag >> > > '' > > here it would be 'mystylesheet.css'. I used the following regex to get > this value(I dont know if it is good). No matter how good it is you should

Re: Regular Expression problem

2006-07-13 Thread cdecarlo
Hey, I'm new with regex's as well but here is my idea. Since you don't know which attribute will come first why don't structure your regex like this (first off, I'll assume that \s == ' ', actually now that I think of it, isn't \s any whitespace character? anyways \s == ' ' for now) '' I think

Re: regular expression problem

2005-05-31 Thread [EMAIL PROTECTED]
thank you again: i used list and not set because order in my list is important. in fact i'd like to apply this function to strings (or ordered sequences of data). For this reason proposed to use regular expression. best regards. -- http://mail.python.org/mailman/listinfo/python-list

Re: regular expression problem

2005-05-31 Thread Kent Johnson
[EMAIL PROTECTED] wrote: > hi everyone > there is a way, using re, to test (for es) in > a=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14] if a list b is > composed by three "sublists" of a separated or not by elements. > > if b=[a2,a3,a4,a7,a8,a12,a13] gives true because in a > we have [,a2,

Re: regular expression problem

2005-05-31 Thread alex23
[EMAIL PROTECTED] wrote: > hi everyone > there is a way, using re, to test (for es) in > a=[a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14] if a list b is > composed by three "sublists" of a separated or not by elements. Heya, Is there any particular reason why you need to use re? If you're usin

Re: Regular Expression Problem...

2004-12-01 Thread Caleb Hattingh
Obviously, Peter and Jorge are hardcore, but below is what a beginner like me hacked up: My point, I guess, is that it is possible to quickly get a solution to a specific problem like this without being a total expert. The code below was typed out once, and with only one minor correction be

Re: Regular Expression Problem...

2004-12-01 Thread Peter Otten
[EMAIL PROTECTED] wrote: > identifying/extracting a substring from another string. What I have to do > is to extract all the strings that begins with a "$" character, but > excluding characters like "." (point) and "'" (single quote) and "\" "/" > (slashes). For example I have: > > 1) This Is An

RE: Regular Expression Problem...

2004-12-01 Thread Doran_Dermot
You could try the following: regex = re.compile("[\$]\w+", re.IGNORECASE) I've only done a bit of testing. Maybe somebody has a better solution. Cheers!! Dermot. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: 01 December 2004

Re: Regular Expression Problem...

2004-12-01 Thread Jorge Godoy
[EMAIL PROTECTED] writes: > #CODE BEGIN > import re > > mystring = "This Is An \$EXAMPLE\String;" > regex = re.compile("[\$]+\S*",re.IGNORECASE) > keys = regex.findall(mystring) > > #CODE END regex = re.compile("[\$]+\w*",re.IGNORECASE) >>> import re >>> >>> mystring = "This Is An \$EXAMPLE\Stri