Wrong Pattern for match_count function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Fabian

    Wrong Pattern for match_count function

    Hi all there,

    Sorry for this newbee question but how comes that the following
    pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";

    does not return any result, while the pattern:
    $r = "%<a href=\"([^>]+?)\"(.*?)>%";

    returns me results, but too many (that's why I wanted to use the first
    pattern, without any luck).

    Called function: $match_count = preg_match_all ($r, $pdata, $items);

    Example of $pdata:
    <td width=80 align=center valign=top><a href="<link that should not be
    grabbed by the pattern>" id=r><img src=image.jpg width=66 height=79
    alt="" border=1><br><f ont size=-2>Bla Bla text</font></a></td><td
    valign=top><a href="<link that should be grabbed by the pattern>"
    id=r>Bla bla text</a><br>

    Can Anyone help, please?

    Thanks.
    Fabian

  • Stefan Heinrichsen

    #2
    Re: Wrong Pattern for match_count function

    Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian" <newspost@hotma il.com>:
    [color=blue]
    > Hi all there,
    >
    > Sorry for this newbee question but how comes that the following
    > pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";
    >
    > does not return any result[...]
    >
    > Example of $pdata:
    > <td width=80 align=center valign=top><a href="[...][/color]
    ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^
    How should this match against "<td valign=top>"? You may try the correct
    <td> line or something like (untested)
    %<td[^>]*><a href=\"([^>]+?)\"(.*?)>% as pattern.

    stefan

    Comment

    • Fabian

      #3
      Re: Wrong Pattern for match_count function


      Stefan Heinrichsen wrote:[color=blue]
      > Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian" <newspost@hotma il.com>:
      >[color=green]
      > > Hi all there,
      > >
      > > Sorry for this newbee question but how comes that the following
      > > pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";
      > >
      > > does not return any result[...]
      > >
      > > Example of $pdata:
      > > <td width=80 align=center valign=top><a href="[...][/color]
      > ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^
      > How should this match against "<td valign=top>"?[/color]

      Thanks for your reply Stefan,

      How should it not? Sorry, I am probably wrong, but I am not familiar
      with regexp and reading the rules...does not help me, in this case

      I need to distinguish this string:
      "<td valign=top><a href...." by this one
      "<td width=80 align=center valign=top><a href...."

      I need to match the first and not the second.

      You may try the correct[color=blue]
      > <td> line or something like (untested)
      > %<td[^>]*><a href=\"([^>]+?)\"(.*?)>% as pattern.[/color]

      BTW, this does not match any pattern at all. (why? shouldn't it return
      any "<td...><a href...>" pattern? it's not what I want, however....)

      If you could clarify. Many thanks.
      Cheers,
      Fabian

      Comment

      • Stefan Heinrichsen

        #4
        Re: Wrong Pattern for match_count function

        Am Mo 09.05.05 um 23:23 CEST schrieb "Fabian" <newspost@hotma il.com>:
        [color=blue]
        >
        > Stefan Heinrichsen wrote:[color=green]
        > > Am Mo 09.05.05 um 16:25 CEST schrieb "Fabian"
        > > <newspost@hotma il.com>:
        > >[color=darkred]
        > > > Hi all there,
        > > >
        > > > Sorry for this newbee question but how comes that the following
        > > > pattern: $r = "%<td valign=top><a href=\"([^>]+?)\"(.*?)>%";
        > > >
        > > > does not return any result[...]
        > > >
        > > > Example of $pdata:
        > > > <td width=80 align=center valign=top><a href="[...][/color]
        > > ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^^^^^
        > > How should this match against "<td valign=top>"?[/color]
        >
        > Thanks for your reply Stefan,
        >
        > How should it not? Sorry, I am probably wrong, but I am not familiar
        > with regexp and reading the rules...does not help me, in this case
        >
        > I need to distinguish this string:
        > "<td valign=top><a href...." by this one
        > "<td width=80 align=center valign=top><a href...."
        >
        > I need to match the first and not the second.[/color]

        Oh sorry my fault. I don't read you $pdata exactly. Is $pdata a exactly
        copy or is it possible that there are any whitespace or somethingelse
        you may forgot?

        stefan

        Comment

        • Fabian

          #5
          Re: Wrong Pattern for match_count function


          Stefan Heinrichsen wrote:[color=blue]
          >
          > Oh sorry my fault. I don't read you $pdata exactly. Is $pdata a[/color]
          exactly[color=blue]
          > copy or is it possible that there are any whitespace or somethingelse
          > you may forgot?[/color]

          It should be the exact copy of what it should be, however I hope to be
          able to add any whitespace information: "\s+" if this would be the
          case.

          Thanks for your help.

          Fabian

          Comment

          Working...