Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82111 > unrolled thread

Re: Python re.search simple question

Started byShiyao Ma <i@introo.me>
First post2014-12-08 15:10 +0800
Last post2014-12-08 15:10 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python re.search simple question Shiyao Ma <i@introo.me> - 2014-12-08 15:10 +0800

#82111 — Re: Python re.search simple question

FromShiyao Ma <i@introo.me>
Date2014-12-08 15:10 +0800
SubjectRe: Python re.search simple question
Message-ID<mailman.16711.1418022637.18130.python-list@python.org>
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.search failing in the below case  ??
>
> >>> pattern
> 'Token-based migrations cannot be mixed with level-based: [prev 0 , now 1]'

I sense a bad smell. Be sure to escape the bracket [ ]

> >>> text
> ' LogMessage {type NDMP_LOG_DBG} {msg_id 0} {msg The process id for NDMP
> service is 0x9c216370} {associated_msg 0} {associated_msg_seq 0} Source
> filer:DartOS  Error: Token-based migrations cannot be mixed with
> level-based: [prev 0 , now 1]'
>
> >>> if (re.search(pattern,text)):
> ...    print "Hi"
> ... else:
> ...     print "BYE"
> ...

so see here: https://bpaste.net/show/d2f1cf66a492 . It prints "HI"

/me always wishes code is sent without others doing some extra formatting before testing.

Hope that helps.




-- 
Shiyao Ma
http://introo.me

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web