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

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',

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

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 '>'

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

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 '$<'

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: 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

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 =

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 =

regular expression problem

2018-10-28 Thread Karsten Hilbert
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*?>\$|\$<[^<:]+?::.*?::\d+-\d+>\$' # it fails if switched

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Because "[\s\w]*" matches only a part of "Bläh": "Bl\xc3". -- ___ Python tracker ___

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Marcus
Marcus added the comment: When I replace the first "ä" with a random letter the untouched expression has not problems to match the second word which contains also an "ä" s = "E-112233-555-11 | Bläh - Bläh" #untuched string s = "E-112233-555-11 | Bloh - Bläh" #string where the first ä is

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Sorry, I don't understand you. If the regex failed to match the first "ä", it can't match the second "ä". Do you have an example? -- ___ Python tracker

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Marcus
Marcus added the comment: Thx for your explanation. You explained why [\s\w] didn't match for "ä". In my situation it didn't matches for the first "ä" but the second time I used [\s\w] in the same regex it matched at the second "ä". What's the explanation for this? --

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: First, in the context of Python a crash means a core dump or an analogue on Windows. In this case the code just works not as you expected. The short answer: s should be a unicode. In your code "ä" is encoded as 8-bit string '\xc3\xa4'. When matched, every

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread SilentGhost
Changes by SilentGhost : -- components: +Regular Expressions nosy: +ezio.melotti, mrabarnett, pitrou, serhiy.storchaka ___ Python tracker

[issue26784] regular expression problem at umlaut handling

2016-04-16 Thread Marcus
nd 3. A change from ä to ö however leeds to a crash again. Ideas? -- messages: 263567 nosy: arbyter priority: normal severity: normal status: open title: regular expression problem at umlaut handling type: behavior versions: Python 2.7 ___ Pytho

Re: Regular expression problem

2013-03-11 Thread jmfauth
On 11 mar, 03:06, Terry Reedy tjre...@udel.edu 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

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 tjre...@udel.edu 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

Re: Regular expression problem

2013-03-11 Thread rusi
On Mar 11, 2:28 pm, jmfauth wxjmfa...@gmail.com wrote: On 11 mar, 03:06, Terry Reedy tjre...@udel.edu 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

On topic, please [Was:Re: Regular expression problem]

2013-03-11 Thread Ned Deily
A friendly reminder that this forum is for general discussion and questions about Python. Pretty much anything Python-related is fair game for discussion, and the group is even fairly tolerant of off-topic digressions; there have been entertaining discussions of topics such as floating point,

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

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

Regular expression problem

2013-03-10 Thread mukesh tiwari
Hello all 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. import re if __name__ == __main__: n = int ( raw_input() ) c = 1 while c = n :

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com 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

Re: Regular expression problem

2013-03-10 Thread Chris Angelico
On Mon, Mar 11, 2013 at 4:59 AM, Chris Angelico ros...@gmail.com wrote: On Mon, Mar 11, 2013 at 4:42 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com 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

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 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 Chris Angelico
On Mon, Mar 11, 2013 at 5:48 AM, mukesh tiwari mukeshtiwari.ii...@gmail.com 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

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

Regular Expression problem

2009-09-08 Thread ���m�ۤv...@����
I have the following source code import re d = 'RTCB\r\nsignature:\xf1\x11

Re: Regular Expression problem

2009-09-08 Thread Vlastimil Brom
2009/9/8 找尋自己的一片天 command@alexbbs.twbbs.org: I have the following source code import re d = 'RTCB\r\nsignature:\xf1\x11

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

a regular expression problem

2008-10-10 Thread lookon
I want to use django to dispatch url. The url is like /test/Google/6,and my patten is r'^/test/(?Pq\b\W+ \b)/(?Ph\d+)$'. It works when the string is English(like Google), but fails when the string is in foreign language. Can anyone tell me the righ regular expression? Thank you! --

Re: a regular expression problem

2008-10-10 Thread Bruno Desthuilliers
lookon a écrit : I want to use django to dispatch url. The url is like /test/Google/6,and my patten is r'^/test/(?Pq\b\W+ \b)/(?Ph\d+)$'. It works when the string is English(like Google), but fails when the string is in foreign language. Care to give an exemple of url that fails ? Anyway, if

Re: a regular expression problem

2008-10-10 Thread Leefurong
I want to use django to dispatch url. The url is like /test/Google/6,and my patten is r'^/test/(?Pq\b\W+ \W should be \w, a typo? :) \b)/(?Ph\d+)$'. It works when the string is English(like Google), but fails when the string is in foreign language. Try this:

a regular expression problem

2008-10-10 Thread gita ziabari
-- Forwarded message -- From: lookon [EMAIL PROTECTED] To: python-list@python.org Date: Fri, 10 Oct 2008 03:58:08 -0700 (PDT) Subject: a regular expression problem I want to use django to dispatch url. The url is like /test/Google/6,and my patten is r'^/test/(?Pq\b\W

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 nextbr /span id=counter_jt_minutes style=display: inline;span id=counter_jt_minutes_value12/

Regular expression problem

2008-06-22 Thread abranches
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 nextbr /span id=counter_jt_minutes style=display: inline;span id=counter_jt_minutes_value12/ spanM/span span id=counter_jt_seconds style=display:

simple regular expression problem

2007-09-17 Thread duikboot
Hello, I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. Could you please help me? s = \norganisatie\nProfiel_Id28996/Profiel_Id\n/organisatie\norganisatie\nProfiel_Id28997/Profiel_Id\n/organisatie regex =

Re: simple regular expression problem

2007-09-17 Thread Jason Drew
You just need a one-character addition to your regex: regex = re.compile(r'organisatie.*?/organisatie', re.S) Note, there is now a question mark (?) after the .* By default, regular expressions are greedy and will grab as much text as possible when making a match. So your original expression

Re: simple regular expression problem

2007-09-17 Thread duikboot
Thank you very much, it works. I guess I didn't read it right. Arjen On Sep 17, 3:22 pm, Jason Drew [EMAIL PROTECTED] wrote: You just need a one-character addition to your regex: regex = re.compile(r'organisatie.*?/organisatie', re.S) Note, there is now a question mark (?) after the .* By

Re: simple regular expression problem

2007-09-17 Thread George Sakkis
On Sep 17, 9:00 am, duikboot [EMAIL PROTECTED] wrote: Hello, I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. Could you please help me? s =

Re: simple regular expression problem

2007-09-17 Thread Jason Drew
You're welcome! Also, of course, parsing XML is a very common task and you might be interested in using one of the standard modules for that, e.g. http://docs.python.org/lib/module-xml.parsers.expat.html Then all the tricky parsing work has been done for you. Jason On Sep 17, 9:31 am,

Re: simple regular expression problem

2007-09-17 Thread Bruno Desthuilliers
duikboot a écrit : Hello, I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. Could you please help me? s = \norganisatie\nProfiel_Id28996/Profiel_Id\n/organisatie\norganisatie\nProfiel_Id28997/Profiel_Id\n/organisatie

Re: simple regular expression problem

2007-09-17 Thread Diez B. Roggisch
duikboot wrote: Hello, I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. Could you please help me? s = \norganisatie\nProfiel_Id28996/Profiel_Id\n/organisatie\norganisatie\nProfiel_Id28997/Profiel_Id\n/organisatie regex =

Re: simple regular expression problem

2007-09-17 Thread Aahz
In article [EMAIL PROTECTED], duikboot [EMAIL PROTECTED] wrote: I am trying to extract a list of strings from a text. I am looking it for hours now, googling didn't help either. To emphasize the other answers you got about avoiding regexps, here's a nice quote from my .sig database: 'Some

regular expression problem

2007-04-30 Thread John Davis
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? Thx John. = -- http://mail.python.org/mailman/listinfo/python-list

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 about

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;fajlink href="" rel=stylesheet type=text/csshere it would be 'mystylesheet.css'. I

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: link type=text/css HREF=mystylesheet.css rel=stylesheet link type=text/css href=mystylesheet.css rel=stylesheet link type='text/css' href='mystylesheet.css' rel='stylesheet' And it's not

Re: Regular Expression problem

2006-07-14 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? link rel=stylesheet href=mystylesheet.css type=text/css -OR- link href=mystylesheet.css rel=stylesheet type=text/css -OR- link type=text/css href=mystylesheet.css

Re: Regular Expression problem

2006-07-14 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 link href=mystylesheet.css rel=stylesheet type=text/css here it would be 'mystylesheet.css'. I used the following regex to get this value(I

Regular Expression problem

2006-07-13 Thread John Blogger
(I don't know if it is the right place. So if I am wrong, please point me the right direction. If this post is read by you masters, I'm honoured. If I am getting a mere response, I'm blessed!) Hi, I'm a newbie regular expression user. I use regex in my Python programs. I have a strange

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)

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 'link href=mystylesheet.css rel=stylesheet type=text/css' here it would be 'mystylesheet.css'. I used the following regex to get this value(I dont know if it

Re: Regular Expression problem

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

regular expression problem

2005-05-31 Thread [EMAIL PROTECTED]
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,a3,a3,...,a7,a8,...,a12,a13,...] or

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 using

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

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

Regular Expression Problem...

2004-12-01 Thread andrea . gavana
Hello NG, I am quite new with Python... I'm writing an application that does also some regexp things on strings, but I'm having problem about 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

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\String; regex =

RE: Regular Expression Problem...

2004-12-01 Thread Doran_Dermot
12:23 To: [EMAIL PROTECTED] Subject: Regular Expression Problem... Hello NG, I am quite new with Python... I'm writing an application that does also some regexp things on strings, but I'm having problem about identifying/extracting a substring from another string. What I have to do

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 $EXAMPLE String