a question on re

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • eight02645999@yahoo.com

    #1

    a question on re

    hi

    i tried to search 2 patterns

    pat1 = re.compile("bla h")
    pat2 = re.compile("bla h2")


    if i do
    if re.findall(pat1 ,something) and re.findall(pat2 ,something):
    do something

    if does not work

    but when i do a nest if,

    if re.findall(pat1 ,something) :
    if re.findall(pat2 ,something):
    do something

    it works..

    please advise on why the first code doesnt work.
    thanks

  • Marco Wahl

    #2
    Re: a question on re

    Hi,
    [color=blue]
    > i tried to search 2 patterns
    >
    > pat1 = re.compile("bla h")
    > pat2 = re.compile("bla h2")
    >
    >
    > if i do
    > if re.findall(pat1 ,something) and re.findall(pat2 ,something):
    > do something
    >
    > if does not work
    >
    > but when i do a nest if,
    >
    > if re.findall(pat1 ,something) :
    > if re.findall(pat2 ,something):
    > do something
    >
    > it works..
    >
    > please advise on why the first code doesnt work.[/color]

    it's not perfectly clear to me what you mean with 'doesnt work'.

    The two if parts
    [color=blue]
    > if re.findall(pat1 ,something) and re.findall(pat2 ,something):
    > do something[/color]

    and
    [color=blue]
    > if re.findall(pat1 ,something) :
    > if re.findall(pat2 ,something):
    > do something[/color]

    look equivalent to me. Could you please reveal your
    value for text-string 'something'? Further I suggest
    to replace the 'do something'-parts with 'print 42'.


    Best wishes Marco

    Comment

    • Fredrik Lundh

      #3
      Re: a question on re

      eight02645999@y ahoo.com wrote
      [color=blue]
      > i tried to search 2 patterns
      >
      > pat1 = re.compile("bla h")
      > pat2 = re.compile("bla h2")
      >
      >
      > if i do
      > if re.findall(pat1 ,something) and re.findall(pat2 ,something):
      > do something
      >
      > if does not work
      >
      > but when i do a nest if,
      >
      > if re.findall(pat1 ,something) :
      > if re.findall(pat2 ,something):
      > do something
      >
      > it works..
      >
      > please advise on why the first code doesnt work.[/color]

      is this the actual code you were using ? and the actual patterns ?
      what's in "something" ?

      </F>



      Comment

      Working...