Re: Correct syntax for pathological re.search()

2024-10-21 Thread Peter J. Holzer via Python-list
On 2024-10-19 00:15:23 +0200, jak via Python-list wrote: > Peter J. Holzer ha scritto: > > As a trivial example, the regular expressions r"\\sout{" and r"\\sout\{" > > are equivalent (the \ before the { is redundant). Yet > > re.compile(s).pattern preserves the difference between the two strings. >

Re: Correct syntax for pathological re.search()

2024-10-19 Thread jak via Python-list
Peter J. Holzer ha scritto: As a trivial example, the regular expressions r"\\sout{" and r"\\sout\{" are equivalent (the \ before the { is redundant). Yet re.compile(s).pattern preserves the difference between the two strings. Hi, Allow me to be fussy: r"\\sout{" and r"\\sout\{" are similar bu

Re: Correct syntax for pathological re.search()

2024-10-18 Thread Peter J. Holzer via Python-list
On 2024-10-12 08:51:57 -0400, Thomas Passin via Python-list wrote: > On 10/12/2024 6:59 AM, Peter J. Holzer via Python-list wrote: > > On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote: > > > Is there some utility function out there that can be called to show what > > > the > > > regul

Re: Correct syntax for pathological re.search()

2024-10-12 Thread Thomas Passin via Python-list
tern) \w+\\sub -Original Message- From: Python-list bounces+avi.e.gross=gmail@python.org> On Behalf Of Gilmeh Serda via Python-list Sent: Friday, October 11, 2024 10:44 AM To: python-list@python.org Subject: Re: Correct syntax for pathological re.search() On Mon, 7 Oct 2024 08:3

RE: Correct syntax for pathological re.search()

2024-10-12 Thread AVI GROSS via Python-list
. -Original Message- From: Python-list On Behalf Of Peter J. Holzer via Python-list Sent: Saturday, October 12, 2024 7:00 AM To: python-list@python.org Subject: Re: Correct syntax for pathological re.search() On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote: > Is there some util

Re: Correct syntax for pathological re.search()

2024-10-12 Thread Thomas Passin via Python-list
On 10/12/2024 6:59 AM, Peter J. Holzer via Python-list wrote: On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote: Is there some utility function out there that can be called to show what the regular expression you typed in will look like by the time it is ready to be used? I assume

Re: Correct syntax for pathological re.search()

2024-10-12 Thread Peter J. Holzer via Python-list
On 2024-10-11 17:13:07 -0400, AVI GROSS via Python-list wrote: > Is there some utility function out there that can be called to show what the > regular expression you typed in will look like by the time it is ready to be > used? I assume that by "ready to be used" you mean the compiled form? No,

Re: Correct syntax for pathological re.search()

2024-10-11 Thread MRAB via Python-list
or pathological re.search() On Mon, 7 Oct 2024 08:35:32 -0500, Michael F. Stemper wrote: I'm trying to discard lines that include the string "\sout{" (which is TeX, for those who are curious. I have tried: if not re.search("\sout{", line): if not re.search("\sout\{

RE: Correct syntax for pathological re.search()

2024-10-11 Thread AVI GROSS via Python-list
cases, ... -Original Message- From: Python-list On Behalf Of Gilmeh Serda via Python-list Sent: Friday, October 11, 2024 10:44 AM To: python-list@python.org Subject: Re: Correct syntax for pathological re.search() On Mon, 7 Oct 2024 08:35:32 -0500, Michael F. Stemper wrote: > I'

Re: Correct syntax for pathological re.search()

2024-10-09 Thread Karsten Hilbert via Python-list
Am Tue, Oct 08, 2024 at 04:59:48PM -0400 schrieb Alan Bawden via Python-list: > Karsten Hilbert writes: > >Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux >Type "help", "copyright", "credits" or "license" for more > information. >>>> tex = '\

Re: Correct syntax for pathological re.search()

2024-10-08 Thread MRAB via Python-list
On 2024-10-08 21:59, Alan Bawden via Python-list wrote: Karsten Hilbert writes: Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> tex = '\sout{' >>> tex

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Alan Bawden via Python-list
Karsten Hilbert writes: Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> tex = '\sout{' >>> tex '\\sout{' >>> Am I missing something ?

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Karsten Hilbert via Python-list
Am Tue, Oct 08, 2024 at 08:07:04PM +0100 schrieb MRAB via Python-list: > >unwanted_tex = '\sout{' > >if unwanted_tex not in line: do_something_with_libreoffice() > > > That should be: > > unwanted_tex = r'\sout{' Hm. Python 3.11.2 (main, Aug 26 2024, 07:20:54) [GCC 12.2.0] on linux

Re: Correct syntax for pathological re.search()

2024-10-08 Thread MRAB via Python-list
On 2024-10-07 14:35, Michael F. Stemper via Python-list wrote: I'm trying to discard lines that include the string "\sout{" (which is TeX, for those who are curious. I have tried: if not re.search("\sout{", line): if not re.search("\sout\{", line):

Re: Correct syntax for pathological re.search()

2024-10-08 Thread MRAB via Python-list
On 2024-10-08 19:30, Karsten Hilbert via Python-list wrote: Am Mon, Oct 07, 2024 at 08:35:32AM -0500 schrieb Michael F. Stemper via Python-list: I'm trying to discard lines that include the string "\sout{" (which is TeX, for those who are curious. I have tried: if not r

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Karsten Hilbert via Python-list
Am Mon, Oct 07, 2024 at 08:35:32AM -0500 schrieb Michael F. Stemper via Python-list: > I'm trying to discard lines that include the string "\sout{" (which is TeX, > for > those who are curious. I have tried: > if not re.search("\sout{", line): > if no

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Jon Ribbens via Python-list
On 2024-10-07, Stefan Ram wrote: > "Michael F. Stemper" wrote or quoted: >>For now, I'll use the "r" in a cargo-cult fashion, until I decide which >>syntax I prefer. (Is there any reason that one or the other is preferable?) > > I'd totally go with the r-style notation! > > It's got one bumme

Correct syntax for pathological re.search()

2024-10-08 Thread Michael F. Stemper via Python-list
I'm trying to discard lines that include the string "\sout{" (which is TeX, for those who are curious. I have tried: if not re.search("\sout{", line): if not re.search("\sout\{", line): if not re.search("\\sout{", line): if not re.search("

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Pieter van Oostrum via Python-list
r...@zedat.fu-berlin.de (Stefan Ram) writes: > "Michael F. Stemper" wrote or quoted: > > path = r'C:\Windows\example' + '\\' > You could even omit the '+'. Then the concatenation is done at parsing time instead of run time. -- Pieter van Oostrum www: http://pieter.vanoostrum.org/ PGP key: [8DA

Re: Correct syntax for pathological re.search()

2024-10-08 Thread Michael F. Stemper via Python-list
On 07/10/2024 08.56, Stefan Ram wrote: "Michael F. Stemper" wrote or quoted: if not re.search("\\sout\{", line): So, if you're not down to slap an "r" before your string literals, you're going to end up doubling down on every backslash. Ne

Re: re.search - Pattern matching review

2016-06-01 Thread Ganesh Pal
Thanks works fine : ) -- https://mail.python.org/mailman/listinfo/python-list

Re: re.search - Pattern matching review

2016-05-30 Thread Matt Wheeler
lock(block): > > cmd = "get_block_info -l" > stdout, stderr, exitcode = subprocess_run(cmd) > #Grab the block from the stdout > block = re.search('(?<=\(block )[^(]*(?=\))', stdout).group() > # check the pattern > matched = re.search(r'(\d+),

Re: re.search - Pattern matching review

2016-05-30 Thread Ganesh Pal
On Sun, May 29, 2016 at 10:32 PM, Matt Wheeler wrote: > > > This doesn't seem to exactly match your code below, i.e. your code is > attempting to construct a tuple from groups 1 through 4. To meet this > specification I could just `return re.search('(?<=\(block &g

Re: re.search - Pattern matching review

2016-05-29 Thread Matt Wheeler
On 28 May 2016 at 19:12, Ganesh Pal wrote: > Dear Python friends, > > I am on Python 2.7 and Linux . I am trying to extract the address > "1,5,147456:8192" from the below stdout using re.search > > (Pdb) stdout > 'linux-host-machine-1: Block Address for 1,5,27

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-29 Thread Ganesh Pal
;, '1375772672', '8192') (Pdb) matched.group() 'Block Address for 1,0,1376034816:8192 (block *1,0,1375772672:8192*' Regards, Ganesh On Sun, May 29, 2016 at 11:53 AM, Ganesh Pal wrote: > > > >> Perhaps: >> map(int, re.search(search_pa

Re: re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
> Perhaps: > map(int, re.search(search_pat, stdout).groups()) > > > Thanks Albert map saved me many lines of code but map returns a list I will have to convert the list to string again Below is how Iam planning to teh conversion >>> block = map(int, re.search(se

RE: re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Albert-Jan Roskam
> Date: Sat, 28 May 2016 23:48:16 +0530 > Subject: re.search - Pattern matching review ( Apologies re sending) > From: ganesh1...@gmail.com > To: python-list@python.org > > Dear Python friends, > > I am on Python 2.7 and Linux . I am trying to extract the address >

re.search - Pattern matching review ( Apologies re sending)

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: m

re.search - Pattern matching review

2016-05-28 Thread Ganesh Pal
Dear Python friends, I am on Python 2.7 and Linux . I am trying to extract the address "1,5,147456:8192" from the below stdout using re.search (Pdb) stdout 'linux-host-machine-1: Block Address for 1,5,27320320:8192 (block 1,5,147456:8192) --\nlinux-host-machine-1: m

Re: Python re.search simple question

2014-12-08 Thread Denis McMahon
prev 0 , now 1] -> match any single character from the set "prev0,now1 " \[prev 0 , now 1\] -> match the actual text [prev 0 , now 1] Try these: re.search('[prev 0 , now 1]','p') # matches (p in "prev0,now1 ") re.search('[prev 0 , now 1]&#x

Re: Python re.search simple question

2014-12-07 Thread Ganesh Pal
to be very trivial question but iam breaking my head > over > > it for a while . > > > > My understanding is that re.search should search for the match anywhere > in > > the string . > > > > > > why is re.search failing in the below case ?? > >

Re: Python re.search simple question

2014-12-07 Thread Jussi Piitulainen
Jussi Piitulainen writes: > Ganesh Pal writes: > > > why is re.search failing in the below case ?? > > Your pattern, '... level-based: [prev 0 , now 1]', matches a literal > string '--- level-based: ' followed by 'p', 'r', 'e

Re: Python re.search simple question

2014-12-07 Thread Zachary Ware
On Mon, Dec 8, 2014 at 12:52 AM, Ganesh Pal wrote: > Hi Folks , > > This might seem to be very trivial question but iam breaking my head over > it for a while . > > My understanding is that re.search should search for the match anywhere in > the string . > > > w

Re: Python re.search simple question

2014-12-07 Thread Shiyao Ma
On Dec 08 at 12:22 +0530, Ganesh Pal wrote: > Hi Folks , > > This might seem to be very trivial question but iam breaking my head over > it for a while . > > My understanding is that re.search should search for the match anywhere in > the string . > > > why is re.se

Re: Python re.search simple question

2014-12-07 Thread Jussi Piitulainen
Ganesh Pal writes: > why is re.search failing in the below case ?? Your pattern, '... level-based: [prev 0 , now 1]', matches a literal string '--- level-based: ' followed by 'p', 'r', 'e', 'v', ' ', '0', ...,

Python re.search simple question

2014-12-07 Thread Ganesh Pal
Hi Folks , This might seem to be very trivial question but iam breaking my head over it for a while . My understanding is that re.search should search for the match anywhere in the string . why is re.search failing in the below case ?? >>> pattern 'Token-based migrations c

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread Steven D'Aprano
On Mon, 07 Jan 2013 01:45:58 -0800, iMath wrote: > 在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道: >> I only know the dollar sign ($) will match a pattern from the >> >> end of a string,but which method does it work with ,re.match() or >> re.search() ? > > I thoug

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2013-01-07 Thread iMath
在 2012年9月26日星期三UTC+8下午3时38分50秒,iMath写道: > I only know the dollar sign ($) will match a pattern from the > > end of a string,but which method does it work with ,re.match() or re.search() > ? I thought re.match('h.$', 'hbxihi') will match ‘hi’ ,bu

RE: re.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Dennis Lee Bieber wrote: > > Unless there has been a major change in the parser... (I still don't > have Python 3.x installed) > > I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF > 8... A tab is *one* character. Your *editor* may show tabs visually "expanded" or conver

RE: re.search when used within an if/else fails

2012-11-29 Thread Prasad, Ramit
Ramit Prasad wrote: > > Dennis Lee Bieber wrote: > > > > Unless there has been a major change in the parser... (I still don't > > have Python 3.x installed) > > > > I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF > > 8... > > A tab is *one* character. Your *editor* may show

Re: re.search when used within an if/else fails

2012-11-29 Thread Duncan Booth
Dennis Lee Bieber wrote: > Unless there has been a major change in the parser... (I still don't > have Python 3.x installed) > > I believe is expanded to 8-spaces -- NOT TO NEXT MULTIPLE OF > 8... > Certainly in Python 2.7 that's not the case: the tab expands to the next multiple o

Re: re.search when used within an if/else fails

2012-11-28 Thread Ian Kelly
On Wed, Nov 28, 2012 at 5:20 PM, Dennis Lee Bieber wrote: > On 28 Nov 2012 21:39:03 GMT, Steven D'Aprano > declaimed the following in > gmane.comp.python.general:> py> if True: > > ... if True: # tab > > ... pass # tab, then four spaces > > ... pass # two spaces, tab, four s

Tabs/spaces for indentation (was Re: re.search when used within an if/else fails)

2012-11-28 Thread Chris Angelico
On Thu, Nov 29, 2012 at 8:39 AM, Steven D'Aprano wrote: > Perhaps it would be nice if Python honoured a directive setting indent > style to spaces or indents, as it honours source code encoding lines: > > # -*- indent: -*- > > Where could be one of: > > space[s]Only accept spaces in inde

Re: re.search when used within an if/else fails

2012-11-28 Thread Steven D'Aprano
On Wed, 28 Nov 2012 14:08:15 -0600, Evan Driscoll wrote: > I'm only entering this thread now so I'm not really in context, but > you're correct; in Python 3, -tt is set by default, which makes illegal > mixing an error. > > However, not all mixing is illegal: what it means by "code that > illegal

Re: re.search when used within an if/else fails

2012-11-28 Thread Steven D'Aprano
On Wed, 28 Nov 2012 11:39:48 -0800, Kevin T wrote: > with other languages i always expand tabs to spaces. the vi plugin does > do this properly. if i change all indents to be spaces only will python > behave? i inherited a good deal of the code that i am using, which is > tab based. Python wil

Re: Re: re.search when used within an if/else fails

2012-11-28 Thread Evan Driscoll
On 11/28/2012 01:57 PM, Ian Kelly wrote: > Yes, it's best to use either tabs-only or spaces-only. Quoting from PEP > 8 on the subject: > > Never mix tabs and spaces. > > The most popular way of indenting Python is with spaces only. The > second-most popular way is with tabs only. Cod

Re: re.search when used within an if/else fails

2012-11-28 Thread Ian Kelly
On Wed, Nov 28, 2012 at 12:39 PM, Kevin T wrote: > with other languages i always expand tabs to spaces. the vi plugin does do this properly. if i change all indents to be spaces only will python behave? i inherited a good deal of the code that i am using, which is tab based. Yes, it's best to

Re: re.search when used within an if/else fails

2012-11-28 Thread Kevin T
I agree. Being relatively new to python, i was not sure of quirks so i posted the original code. I did find the real issue, as I found another loop that was not being executed properly. It turns out that if the indent started with spaces and ended with tabs, neither eclipse or command line e

Re: re.search when used within an if/else fails

2012-11-21 Thread Chris Angelico
On Thu, Nov 22, 2012 at 3:41 AM, Kevin T wrote: > I went back and tried version a again, blam it is/does work now ?!?!? > I am not sure what changed but version a was the original code that > wouldn't work. All the examples i had read, showed version a as a > working version. I spent significant

Re: re.search when used within an if/else fails

2012-11-21 Thread Kevin T
On Nov 20, 1:37 pm, Ian Kelly wrote: > On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote: > > #if re.search( "rsrvd", sigName ) :   #version a > > #if re.search( "rsrvd", sigName ) == None :   #version b > > if re.search( "rsrvd", sig

Re: re.search when used within an if/else fails

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 12:37 PM, Ian Kelly wrote: > On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote: >> #if re.search( "rsrvd", sigName ) : #version a >> #if re.search( "rsrvd", sigName ) == None : #version b >> if re.search( "rsrvd", si

Re: re.search when used within an if/else fails

2012-11-20 Thread Ian Kelly
On Tue, Nov 20, 2012 at 12:09 PM, Kevin T wrote: > #if re.search( "rsrvd", sigName ) : #version a > #if re.search( "rsrvd", sigName ) == None : #version b > if re.search( "rsrvd", sigName ) is None : #version bb >print sigName >n

Re: re.search when used within an if/else fails

2012-11-20 Thread Kevin T
nt taken i will change ==/!= to is/is not as most people pointed out. there is no else because it doesn't work. i used eclipse in debug mode and a command line execution of the code, both behave the same way #if re.search( "rsrvd", sigName ) : #version a #if re.search( "rs

Re: re.search when used within an if/else fails

2012-11-19 Thread Steven D'Aprano
sigName = signal['functionName'] 352 > if re.search( "rsrvd", sigName ) == None : 353 > print sigName 354 newVal = "%s%s" % ( > '1'*signal['bits'] , ne

Re: re.search when used within an if/else fails

2012-11-19 Thread Steven D'Aprano
On Tue, 20 Nov 2012 01:24:54 +, Steven D'Aprano wrote: > Your code is mangled to the point of unreadability. Ah, never mind, that's *my* fault, not yours. Or rather, my news reader software. Sorry about the noise. The rest of my post still stands: - simplify your example to the simplest e

Re: re.search when used within an if/else fails

2012-11-19 Thread MRAB
ctionName'] 352 if re.search( "rsrvd", sigName ) == None : 353 print sigName 354 newVal = "%s%s" % ( '1'*signal['bits'] , newVal ) #prepend 0's 355 if re.search( "

re.search when used within an if/else fails

2012-11-19 Thread Kevin T
python version 2.4.3, yes i know that it is old. getting the sysadmin to update the OS requires a first born. with the following code.. for signal in register['signals'] : 351 sigName = signal['functionName'] 352

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-28 Thread Ian Kelly
On Fri, Sep 28, 2012 at 12:07 PM, Prasad, Ramit wrote: > I guess you can consider re.match's pattern to be > prefixed with '^'. You can in this case, but they're not equivalent in multi-line mode: >>> re.match('^two', 'one\ntwo', re.M)

RE: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-28 Thread Prasad, Ramit
iMath wrote: > Sent: Wednesday, September 26, 2012 2:39 AM > To: python-list@python.org > Subject: regular expression : the dollar sign ($) work with re.match() or > re.search() ? > > I only know the dollar sign ($) will match a pattern from the > end of a string,but whic

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Jussi Piitulainen
Alister writes: > On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote: > > > iMath writes: > > > >> I only know the dollar sign ($) will match a pattern from the end > >> of a string, but which method does it work with, re.match() or > >>

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Alister
On Wed, 26 Sep 2012 10:48:00 +0300, Jussi Piitulainen wrote: > iMath writes: > >> I only know the dollar sign ($) will match a pattern from the end of a >> string, but which method does it work with, re.match() or re.search() > > It works with both. With re.match, the

Re: regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-26 Thread Peter Otten
iMath wrote: > I only know the dollar sign ($) will match a pattern from the > end of a string,but which method does it work with ,re.match() or > re.search() ? Why not try it out in the interactive interpreter? Here's the "deluxe version": >>> def demo(patt

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Chris Angelico
On Wed, Sep 26, 2012 at 5:48 PM, Jussi Piitulainen wrote: > What was the weird character that you used as a question mark? I > removed them because they confuse the newsreader I use. It appears to be Unicode Character 'FULLWIDTH QUESTION MARK' (U+FF1F). Normally I'd be inclined to simply use U+00

Re: regular expression : the dollar sign ($) work with re.match() or re.search()

2012-09-26 Thread Jussi Piitulainen
iMath writes: > I only know the dollar sign ($) will match a pattern from the end of > a string, but which method does it work with, re.match() or > re.search() It works with both. With re.match, the pattern has to match at the start of the string _and_ the $ has to match the end of t

regular expression : the dollar sign ($) work with re.match() or re.search() ?

2012-09-26 Thread iMath
I only know the dollar sign ($) will match a pattern from the end of a string,but which method does it work with ,re.match() or re.search() ? -- http://mail.python.org/mailman/listinfo/python-list

Re: help regarding re.search

2011-09-15 Thread Sagar Neve
Hey Thanks. I just resolved it and yes you are right there was a (hidden) new-line to it. I found it in a crude way of putting dots before and after. I was to post about it here and saw your message. I was not knowing about %r. Thanks for that. Thats a good addition to my knowledge. Thanks a bu

Re: help regarding re.search

2011-09-15 Thread Gelonida N
Hi Sagar, In order to be able to help you I propose following: On 09/15/2011 06:54 AM, Sagar Neve wrote: . . . > print "hello..Man_Param=%s,Opt_Param1=%s, > Opt_Param2=%s\n" %(Man_Param,Opt_Param1,Opt_Param2) Change above line into > print "hello..Man_Par

Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Yes. It is been resolved now for the sample program. however, as mentioned in other post. It is not working in the main program On Thu, Sep 15, 2011 at 10:25 AM, Kushal Kumaran < kushal.kumaran+pyt...@gmail.com> wrote: > On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve wrote: > > Here is the code >

Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:55 PM, Kushal Kumaran wrote: > That looks like a bash error message.  Syntax errors in python show up > with a stack trace.  Run your program using the python interpreter > like this: > > python file.py > OR > python3 file.py > > whatever is applicable in your environment

Re: help regarding re.search

2011-09-14 Thread Kushal Kumaran
On Thu, Sep 15, 2011 at 10:11 AM, Sagar Neve wrote: > Here is the code > > > url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa"; > > Man_Param="/us/r1000" > Opt_Param1="Purple" > Opt_Param2="dpkg.ipa" > > if (Opt_Param2 in url): >     print "hello." > else: >     print "

Re: help regarding re.search

2011-09-14 Thread Sagar Neve
; instead it should qualify. for key in dictionary: m=re.search(key, url) if m !=None: values=dictionary[key] for v in values: v_array=v.split(',') Man_Param

Re: help regarding re.search

2011-09-14 Thread Chris Angelico
On Thu, Sep 15, 2011 at 2:41 PM, Sagar Neve wrote: > ./sample.py: line 9: syntax error near unexpected token `:' > ./sample.py: line 9: `if (Opt_Param2 in url):    ' > It worked for me in Python 3.2. What version of Python are you using? ChrisA -- http://mail.python.org/mailman/listinfo/python-

Re: help regarding re.search

2011-09-14 Thread Sagar Neve
Here is the code url="http://xy.yz.com/us/r1000/012/Purple/b1/c6/e2/mzm.dxkjsfbl..d2.dpkg.ipa " Man_Param="/us/r1000" Opt_Param1="Purple" Opt_Param2="dpkg.ipa" if (Opt_Param2 in url): print "hello." else: print "bye." It gives me: ./sample.py: line 9: syntax error near unexpected tok

Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 8:33 PM, Sagar Neve wrote: > If A in B: > does nt seem to be working. > Am I missing something here. Please provide a snippet of the code in question, and be specific about how it's not working. Cheers, Chris -- http://rebertia.com -- http://mail.python.org/mailman/listi

Re: help regarding re.search

2011-09-14 Thread Sagar Neve
If A in B: does nt seem to be working. Am I missing something here. -$agar On Sep 15, 2011 7:25 AM, "Chris Rebert" wrote: > On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve wrote: >> Hi, >> I have a small program where I want to do just a small regex operation. >> I want to see if value of a variable

Re: help regarding re.search

2011-09-14 Thread Chris Rebert
On Wed, Sep 14, 2011 at 6:41 PM, Sagar Neve wrote: > Hi, > I have a small program where I want to do just a small regex operation. > I want to see if value of a variable 'A' is present in an another variable > 'B'.  The below code works fine but as soon as the variable 'A' has some > string includ

help regarding re.search

2011-09-14 Thread Sagar Neve
it fails. for example say: B="dpkg.ipaz The code works fine when A="dpkg" however the code does not work when A="dpkg.ipa" if re.search(A,B): # do something. Can somebody please help me ? -- http://mail.python.org/mailman/listinfo/python-list

help regarding re.search

2011-09-14 Thread Sagar Neve
it fails. for example say: B="dpkg.ipaz The code works fine when A="dpkg" however the code does not work when A="dpkg.ipa" if re.search(A,B): # do something. Can somebody please help me ? -- http://mail.python.org/mailman/listinfo/python-list

Re: returning all matching groups with re.search()

2011-02-11 Thread MRAB
On 11/02/2011 04:34, Roland Mueller wrote: Hello, On 02/07/2011 06:26 PM, Mauro Caceres wrote: >>> import re >>> help(re.findall) Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are prese

Re: returning all matching groups with re.search()

2011-02-10 Thread Roland Mueller
Hello, On 02/07/2011 06:26 PM, Mauro Caceres wrote: >>> import re >>> help(re.findall) Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list

Re: returning all matching groups with re.search()

2011-02-07 Thread Mauro Caceres
>>> import re >>> help(re.findall) Help on function findall in module re: findall(pattern, string, flags=0) Return a list of all non-overlapping matches in the string. If one or more groups are present in the pattern, return a list of groups; this will be a list of tuples if the patte

Re: returning all matching groups with re.search()

2011-02-03 Thread Benjamin Kaplan
On Thu, Feb 3, 2011 at 3:32 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote: > Here's a scenario: > > import re > m = re.search('e','fredbarneybettywilma') > > Now, here's a stupid question: > why doesn't m.groups() r

Re: returning all matching groups with re.search()

2011-02-03 Thread Chris Rebert
On Thu, Feb 3, 2011 at 12:32 PM, mhearne808[insert-at-sign-here]gmail[insert-dot-here]com wrote: > Here's a scenario: > > import re > m = re.search('e','fredbarneybettywilma') > > Now, here's a stupid question: > why doesn't m.grou

returning all matching groups with re.search()

2011-02-03 Thread mhearne808[insert-at-sign-here]gmail[insert-dot-here]com
Here's a scenario: import re m = re.search('e','fredbarneybettywilma') Now, here's a stupid question: why doesn't m.groups() return ('e','e','e'). I'm trying to figure out how to match ALL of the instances of a pattern in o

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-26 Thread Aahz
In article , Phlip wrote: > >Thanks all for playing! And as usual I forgot a critical detail: > >I'm writing a matcher for a Morelia /viridis/ Scenario step, so the >matcher must be a single regexp. Why? (You're apparently the author of Morelia, but I don't really understand it.) -- Aahz (a...

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread MRAB
On 25/11/2010 19:57, Phlip wrote: Accepting input from a human is fraught with dangers and edge cases. Here's a non-regex solution Thanks all for playing! And as usual I forgot a critical detail: I'm writing a matcher for a Morelia /viridis/ Scenario step, so the matcher must be a single re

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread Phlip
+), )? (?:(\w+), and )?(\w+)$', 'whatever a, bbb, and c') print got # [('a', '', '', '', 'bbb', 'c')] The trick is to simply paste in a high number of (?:(\w+), )? segments, assuming that nobody should plug in too

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread MRAB
On 25/11/2010 04:46, Phlip wrote: HypoNt: I need to turn a human-readable list into a list(): print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c').groups() That currently returns ('c',). I'm trying to match "any word \w+ followed by

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread Steve Holden
On 11/24/2010 10:46 PM, Phlip wrote: > HypoNt: > > I need to turn a human-readable list into a list(): > >print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and > c').groups() > > That currently returns ('c',). I'm tryi

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread python
Phlip, > I'm trying to match "any word \w+ followed by a comma, or a final word > preceded by and." Here's a non-regex solution that handles multi-word values and multiple instances of 'and' (as pointed out by Alice). The posted code could be simplified via list comprehension - I chose the more

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread Alice Bevan–McGregor
Now that I think about it, and can be stripped using a callback function as the 'normalize' argument to my KeywordProcessor class: def normalize(value): value = value.strip() if value.startswith("and"): value = value[3:] return value parser = KeywordProcessor(',', normalize=no

Re: a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-25 Thread Alice Bevan–McGregor
Accepting input from a human is frought with dangers and edge cases. ;) Some time ago I wrote a regular expression generator that creates regexen that can parse arbitrarily delimited text, supports quoting (to avoid accidentally separating two elements that should be treated as one), and work

Re: a regexp riddle: re.search(r'

2010-11-25 Thread Yingjie Lan
--- On Thu, 11/25/10, Phlip wrote: > From: Phlip > Subject: a regexp riddle: re.search(r' > To: python-list@python.org > Date: Thursday, November 25, 2010, 8:46 AM > HypoNt: > > I need to turn a human-readable list into a list(): > >    print re.search(r'(

a regexp riddle: re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c') =? ('a', 'bbb', 'c')

2010-11-24 Thread Phlip
HypoNt: I need to turn a human-readable list into a list(): print re.search(r'(?:(\w+), |and (\w+))+', 'whatever a, bbb, and c').groups() That currently returns ('c',). I'm trying to match "any word \w+ followed by a comma, or a final word preceded by

Re: re.search over a list

2008-10-23 Thread Pat
Bruno Desthuilliers wrote: Pat a écrit : Bruno Desthuilliers wrote: Pat a écrit : While I can use a for loop looking for a match on a list, I was wondering if there was a one-liner way. In particular, one of my RE's looks like this '^somestring$' so I can't jus

Re: re.search over a list

2008-10-23 Thread Bruno Desthuilliers
Steve Holden a écrit : Pat wrote: Bruno Desthuilliers wrote: (snip) words = ['foo', 'bar', 'somestring', 'baaz'] re.search(r"^somestring$", "\n".join(words), re.MULTILINE) (snip) I suspect that any(re.match(pat, word)

Re: re.search over a list

2008-10-22 Thread Steve Holden
Pat wrote: > Bruno Desthuilliers wrote: >> Pat a écrit : >>> While I can use a for loop looking for a match on a list, I was >>> wondering if there was a one-liner way. >>> >>> In particular, one of my RE's looks like this '^somestring$'

Re: re.search over a list

2008-10-20 Thread Bruno Desthuilliers
Pat a écrit : Bruno Desthuilliers wrote: Pat a écrit : While I can use a for loop looking for a match on a list, I was wondering if there was a one-liner way. In particular, one of my RE's looks like this '^somestring$' so I can't just do this: re.search( '^

Re: re.search over a list

2008-10-20 Thread Pat
Bruno Desthuilliers wrote: Pat a écrit : While I can use a for loop looking for a match on a list, I was wondering if there was a one-liner way. In particular, one of my RE's looks like this '^somestring$' so I can't just do this: re.search( '^somestring$', s

Re: re.search over a list

2008-10-19 Thread Bruno Desthuilliers
Pat a écrit : While I can use a for loop looking for a match on a list, I was wondering if there was a one-liner way. In particular, one of my RE's looks like this '^somestring$' so I can't just do this: re.search( '^somestring$', str( mylist ) ) I'm not

  1   2   >