RE: Python regex pattern from array of hex chars

2018-04-13 Thread Joseph L. Casale
-Original Message- From: Python-list On Behalf Of MRAB Sent: Friday, April 13, 2018 12:05 PM To: python-list@python.org Subject: Re: Python regex pattern from array of hex chars > Use re.escape: > > regex = re.compile('[^{}]+'.format(re.escape(''.join

Re: Python regex pattern from array of hex chars

2018-04-13 Thread MRAB
On 2018-04-13 18:28, Joseph L. Casale wrote: I have an array of hex chars which designate required characters. and one happens to be \x5C or "\". What foo is required to build the pattern to exclude all but: regex = re.compile('[^{}]+'.format(''.join(c for c in character_class))) I would use th

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Marko Rauhamaa
Jussi Piitulainen : > Michael Torrie writes: > >> On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: >>> Marko Rauhamaa writes: And nothing in alister's answer suggests that. >>> >>> Now *I'm* surprised. >> >> He simply said, here's a regex that can parse the example string the OP >> gave us (

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Jussi Piitulainen
Michael Torrie writes: > On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: >> Marko Rauhamaa writes: >>> And nothing in alister's answer suggests that. >> >> Now *I'm* surprised. > > He simply said, here's a regex that can parse the example string the OP > gave us (which maybe looked a bit like HT

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Michael Torrie
On 06/15/2016 08:57 AM, Jussi Piitulainen wrote: > Marko Rauhamaa writes: >> And nothing in alister's answer suggests that. > > Now *I'm* surprised. He simply said, here's a regex that can parse the example string the OP gave us (which maybe looked a bit like HTML, but like you say, may not be),

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Jussi Piitulainen
alister writes: > On Wed, 15 Jun 2016 15:55:42 +0300, Jussi Piitulainen wrote: > >> alister writes: >> >>> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >>> Hi everyone, I am struggling writing a right regex that match what I want: Problem Description: Give

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread alister
On Wed, 15 Jun 2016 15:55:42 +0300, Jussi Piitulainen wrote: > alister writes: > >> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >> >>> Hi everyone, >>> I am struggling writing a right regex that match what I want: >>> >>> Problem Description: >>> >>> Given a string like this: >>> >>>

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Jussi Piitulainen
Marko Rauhamaa writes: > Jussi Piitulainen writes: > >> alister writes: >> >>> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: Given a string like this: >>>string = "false_head aaa bbb false_tail \ true_head some_text_here ccc ddd eee t

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Marko Rauhamaa
Jussi Piitulainen : > alister writes: > >> On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: >>> Given a string like this: >>> >>> >>>string = "false_head aaa bbb false_tail \ >>> true_head some_text_here ccc ddd eee >>> true_tail" >>> >>> I want to match the all

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Jussi Piitulainen
alister writes: > On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: > >> Hi everyone, >> I am struggling writing a right regex that match what I want: >> >> Problem Description: >> >> Given a string like this: >> >> >>>string = "false_head aaa bbb false_tail \ >> true_head

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread alister
On Tue, 14 Jun 2016 20:28:24 -0700, Yubin Ruan wrote: > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee >

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Lawrence D’Oliveiro
On Wednesday, June 15, 2016 at 3:28:37 PM UTC+12, Yubin Ruan wrote: > I want to match the all the text surrounded by those " ", You are trying to use regex (type 3 grammar) to parse HTML (type 2 grammar) ? No can do

Re: python regex: variable length of positive lookbehind assertion

2016-06-15 Thread Vlastimil Brom
2016-06-15 5:28 GMT+02:00 Yubin Ruan : > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee > true_tail" > > I w

Re: python regex: variable length of positive lookbehind assertion

2016-06-14 Thread Jussi Piitulainen
Yubin Ruan writes: > Hi everyone, > I am struggling writing a right regex that match what I want: > > Problem Description: > > Given a string like this: > > >>>string = "false_head aaa bbb false_tail \ > true_head some_text_here ccc ddd eee > true_tail" > > I want to match the a

Re: python regex: variable length of positive lookbehind assertion

2016-06-14 Thread Yubin Ruan
On Wednesday, June 15, 2016 at 12:18:31 PM UTC+8, Lawrence D’Oliveiro wrote: > On Wednesday, June 15, 2016 at 3:28:37 PM UTC+12, Yubin Ruan wrote: > > > I want to match the all the text surrounded by those " ", > > You are trying to use regex (type 3 grammar) to parse HTML (type 2 grammar) >

Re: Python regex exercise

2015-04-04 Thread Vincent Davis
On Sat, Apr 4, 2015 at 5:51 PM, Thomas 'PointedEars' Lahn < pointede...@web.de> wrote: > > Do anyone have good links to python regex or other python problems for > > beginners but with solution. > > > > Please mail me. > ​I recently found​ this https://regex101.com/#python Vincent Davis 720-301

Re: Python regex exercise

2015-04-04 Thread Thomas 'PointedEars' Lahn
Robert Clove wrote: > Do anyone have good links to python regex or other python problems for > beginners but with solution. > > Please mail me.

Re: python regex "negative lookahead assertions" problems

2009-11-23 Thread Helmut Jarausch
On 11/22/09 16:05, Helmut Jarausch wrote: On 11/22/09 14:58, Jelle Smet wrote: Hi List, I'm trying to match lines in python using the re module. The end goal is to have a regex which enables me to skip lines which have ok and warning in it. But for some reason I can't get negative lookaheads wo

Re: python regex "negative lookahead assertions" problems

2009-11-22 Thread MRAB
Tim Chase wrote: import re line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' re.match('.*(?!warning)',line) <_sre.SRE_Match object at 0xb75b1598> I would expect that this would NOT

Re: python regex "negative lookahead assertions" problems

2009-11-22 Thread Helmut Jarausch
On 11/22/09 14:58, Jelle Smet wrote: Hi List, I'm trying to match lines in python using the re module. The end goal is to have a regex which enables me to skip lines which have ok and warning in it. But for some reason I can't get negative lookaheads working, the way it's explained in "http://

Re: python regex "negative lookahead assertions" problems

2009-11-22 Thread Tim Chase
import re line='2009-11-22 12:15:441 lmqkjsfmlqshvquhsudfhqf qlsfh qsduidfhqlsiufh qlsiuf qldsfhqlsifhqlius dfh warning qlsfj lqshf lqsuhf lqksjfhqisudfh qiusdfhq iusfh' re.match('.*(?!warning)',line) <_sre.SRE_Match object at 0xb75b1598> I would expect that this would NOT match as it's a neg

Re: Python Regex Question

2008-10-29 Thread Terry Reedy
MalteseUnderdog wrote: Hi there I just started python (but this question isn't that trivial since I couldn't find it in google :) ) I have the following text file entries (simplified) start #frag 1 start x=Dog # frag 1 end stop start# frag 2 start x=Cat # frag 2 end stop start #fra

Re: Python Regex Question

2008-10-29 Thread Arnaud Delobelle
On Oct 29, 7:01 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > > I need a regex expression which returns the start to the x=ANIMAL for > > only the x=Dog fragments so all my entries should be start ... > > (something here) ... x=Dog .  So I am really interested in fragments 1 > > and 3 only. > > > My i

Re: Python Regex Question

2008-10-29 Thread Tim Chase
I need a regex expression which returns the start to the x=ANIMAL for only the x=Dog fragments so all my entries should be start ... (something here) ... x=Dog . So I am really interested in fragments 1 and 3 only. My idea (primitive) ^start.*?x=Dog doesn't work because clearly it would return r

Re: python regex character group matches

2008-09-17 Thread Fredrik Lundh
Steven D'Aprano wrote: Assuming that you want to find runs of \u escapes, simply use non-capturing parentheses: pat = re.compile(u"(?:\\\u[0-9A-F]{4})") Doesn't work for me: pat = re.compile(u"(?:\\\u[0-9A-F]{4})") it helps if you cut and paste the right line... here's a better v

Re: python regex character group matches

2008-09-17 Thread Steven D'Aprano
On Wed, 17 Sep 2008 09:27:47 -0400, christopher taylor wrote: > hello python-list! > > the other day, i was trying to match unicode character sequences that > looked like this: > > \\uAD0X... It is not clear what this is supposed to be. Is that matching a literal pair of backslashes, or a sing

Re: python regex character group matches

2008-09-17 Thread Steven D'Aprano
On Wed, 17 Sep 2008 15:56:31 +0200, Fredrik Lundh wrote: > Assuming that you want to find runs of \u escapes, simply use > non-capturing parentheses: > > pat = re.compile(u"(?:\\\u[0-9A-F]{4})") Doesn't work for me: >>> pat = re.compile(u"(?:\\\u[0-9A-F]{4})") UnicodeDecodeError: 'unico

Re: python regex character group matches

2008-09-17 Thread Fredrik Lundh
christopher taylor wrote: my issue, is that the pattern i used was returning: [ '\\uAD0X', '\\u1BF3', ... ] when i expected: [ '\\uAD0X\\u1BF3', ] the code looks something like this: pat = re.compile("(\\\u[0-9A-F]{4})+", re.UNICODE|re.LOCALE) #print pat.findall(txt_line) results = pat.find

Re: python regex character group matches

2008-09-17 Thread Marc 'BlackJack' Rintsch
On Wed, 17 Sep 2008 09:27:47 -0400, christopher taylor wrote: > the other day, i was trying to match unicode character sequences that > looked like this: > > \\uAD0X... > > my issue, is that the pattern i used was returning: > > [ '\\uAD0X', '\\u1BF3', ... ] > > when i expected: > > [ '\\uAD0X

Re: Python regex question

2008-08-15 Thread Tim N. van der Leeuw
Hey Gerhard, Gerhard Häring wrote: > > Tim van der Leeuw wrote: >> Hi, >> >> I'm trying to create a regular expression for matching some particular >> XML strings. I want to extract the contents of a particular XML tag, >> only if it follows one tag, but not follows another tag. Complicating

Re: Python regex question

2008-06-11 Thread Gerhard Häring
Tim van der Leeuw wrote: Hi, I'm trying to create a regular expression for matching some particular XML strings. I want to extract the contents of a particular XML tag, only if it follows one tag, but not follows another tag. Complicating this, is that there can be any number of other tags in

Re: Python regex

2008-03-13 Thread Adonis Vargas
Andrew Rekdal < wrote: > I hope posting is ok here for this question... > > I am attempting to extract the text from a CSS comment using 're' such as... > > string = "/* CSS comment /*" > exp = "[^(/*)].*[^(*/)] " > > p = re.compile(exp) > q = p.search(string) > r = q.group() > > print r > >>>

Re: Python regex

2008-03-13 Thread Arnaud Delobelle
On Mar 13, 8:22 pm, "Andrew Rekdal" <@comcast.net> wrote: [...] > in your expression above.. > > >>> r = re.compile(r'/\*(.*?)\*/') > > what does the 'r' do? It means the literal is a 'raw string' : >>> print 'Hi\nthere!' Hi there! >>> print r'Hi\nthere!' Hi\nthere! >>> If you haven't done so al

Re: Python regex

2008-03-13 Thread "Andrew Rekdal"
-- -- Andrew "Arnaud Delobelle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] On Mar 13, 8:03 pm, "Andrew Rekdal" <@comcast.net> wrote: > I hope posting is ok here for this question... > > I am attempting to extract the text from a CSS comment using 're' such > as... > > string

Re: Python regex

2008-03-13 Thread Arnaud Delobelle
On Mar 13, 8:03 pm, "Andrew Rekdal" <@comcast.net> wrote: > I hope posting is ok here for this question... > > I am attempting to extract the text from a CSS comment using 're' such as... > > string = "/* CSS comment /*" > exp = "[^(/*)].*[^(*/)] " > > p = re.compile(exp) > q = p.search(string) > r

Re: Python regex

2008-03-13 Thread "Andrew Rekdal"
made error on last line... read as... > I would be saying if forward-slash AND asterisk appear in this order... > negate -- -- Andrew "Andrew Rekdal @comcast.net>" < wrote in message news:[EMAIL PROTECTED] >I hope posting is ok here for this question... > > I am attempting to extract the tex

Re: python regex: misbehaviour with "\r" (0x0D) as Newline character in Unicode Mode

2008-01-27 Thread Fredrik Lundh
Arian Sanusi wrote: > concerning to unicode, "\n", "\r "and "\r\n" (0x000A, 0x000D and 0x000D+0x000A) should be threatened as newline character the link says that your application should treat them line terminators, not that they should all be equal to a new line character. to split on Unicode

Re: python/regex question... hope someone can help

2007-12-09 Thread Gabriel Genellina
En Sun, 09 Dec 2007 16:45:53 -0300, charonzen <[EMAIL PROTECTED]> escribió: >> [John Machin] Another suggestion is to ensure that the job >> specification is not >> overly simplified. How did you parse the text into "words" in the >> prior exercise that produced the list of bigrams? Won't you

Re: python/regex question... hope someone can help

2007-12-09 Thread charonzen
> Another suggestion is to ensure that the job specification is not > overly simplified. How did you parse the text into "words" in the > prior exercise that produced the list of bigrams? Won't you need to > use the same parsing method in the current exercise of tagging the > bigrams with an under

Re: python/regex question... hope someone can help

2007-12-09 Thread John Machin
On Dec 9, 6:13 pm, charonzen <[EMAIL PROTECTED]> wrote: The following *may* come close to doing what your revised spec requires: import re def ch_replace2(alist, text): for bigram in alist: pattern = r'\b' + bigram.replace('_', ' ') + r'\b' text = re.sub(pattern, bigram, text)

Re: python/regex question... hope someone can help

2007-12-09 Thread John Machin
On Dec 9, 6:13 pm, charonzen <[EMAIL PROTECTED]> wrote: > I have a list of strings. These strings are previously selected > bigrams with underscores between them ('and_the', 'nothing_given', and > so on). I need to write a regex that will read another text string > that this list was derived from

Re: Python Regex Question

2007-09-21 Thread David
> re.search(expr, string) compiles and searches every time. This can > potentially be more expensive in calculating power. especially if you > have to use the expression a lot of times. The re module-level helper functions cache expressions and their compiled form in a dict. They are only compiled

Re: Python Regex Question

2007-09-21 Thread Ivo
crybaby wrote: > On Sep 20, 4:12 pm, Tobiah <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >>> I need to extract the number on each >> i.e 49.950 from the following: >>>  49.950  >>> The actual number between:  49.950  can be any number of >>> digits before decimal and after decimal. >>>  #

Re: Python Regex Question

2007-09-20 Thread crybaby
On Sep 20, 4:12 pm, Tobiah <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I need to extract the number on each > > i.e 49.950 from the following: > > >  49.950  > > > The actual number between:  49.950  can be any number of > > digits before decimal and after decimal. > > >  ##.

Re: Python Regex Question

2007-09-20 Thread Gerardo Herzig
[EMAIL PROTECTED] wrote: >I need to extract the number on each >i.e 49.950 from the following: > > 49.950  > >The actual number between:  49.950  can be any number of >digits before decimal and after decimal. > > ##.  > >How can I just extract the real/integer number using regex? > > >

Re: Python Regex Question

2007-09-20 Thread Tobiah
[EMAIL PROTECTED] wrote: > I need to extract the number on each > i.e 49.950 from the following: > >  49.950  > > The actual number between:  49.950  can be any number of > digits before decimal and after decimal. > >  ##.  > > How can I just extract the real/integer number using rege

Re: python - regex handling

2006-07-04 Thread Paolo Pantaleo
2006/7/4, bruce <[EMAIL PROTECTED]>: > hi... > > does python provide regex handling similar to perl. can't find anything in > the docs i've seen to indicate it does... > > -bruce > > -- > http://mail.python.org/mailman/listinfo/python-list > http://python.org/doc/2.4.1/lib/module-re.html Here is t

Re: python - regex handling

2006-07-04 Thread Ravi Teja
bruce wrote: > hi... > > does python provide regex handling similar to perl. can't find anything in > the docs i've seen to indicate it does... > > -bruce It helps to learn to search before asking for help. Typing the words - python regex (words from your post) into Google gives you plenty of res

Re: python - regex handling

2006-07-04 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, bruce wrote: > does python provide regex handling similar to perl. can't find anything in > the docs i've seen to indicate it does... The `re` module handles Perl compatible regexes. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python