preg_match

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

    preg_match

    Please can someone help me with this before I explode!!! (no pun intended)

    <?php
    // EXAMPLE 1
    $text = "This is Driving me mad";
    $check = "Driving";
    $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[ ])";
    preg_match($ss, $text,$check);
    echo "result = $check[0]"; //gives a result

    echo "<br>";

    // EXAMPLE 2
    $text = "This is Driving me mad";
    $check = "driving"; // NOTE CHANGE Driving to driving
    $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[ ])";
    preg_match($ss, $text,$check);
    echo "result = $check[0]"; // gives nothing.

    ?>


    According to php.net /i is required to make it case sensitive, so why is
    this happening?!?!

    Nel.



    --
    DISCLAIMER: There is an extremely small but nonzero chance that,
    through a process known as "Tunneling" , this e-mail may spontaneously
    disappear from its present location and reappear at any random place in the
    Universe, including your neighbour's domicile. The sender will not be
    responsible for any damages or inconvenience that may result.


  • Justin Koivisto

    #2
    Re: preg_match

    Nel wrote:
    [color=blue]
    > Please can someone help me with this before I explode!!! (no pun intended)
    >
    > $check = "Driving";
    > $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[ ])";
    > preg_match($ss, $text,$check);
    >
    > $check = "driving"; // NOTE CHANGE Driving to driving
    > $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[ ])";
    > preg_match($ss, $text,$check);
    >
    > According to php.net /i is required to make it case sensitive, so why is
    > this happening?!?![/color]

    Becuase you don't have it there???

    $ss = "`([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[
    ])`i";

    --
    Justin Koivisto - spam@koivi.com

    Comment

    • Nel

      #3
      Re: preg_match

      "Justin Koivisto" <spam@koivi.com > wrote in message
      news:HjIXc.1092 $j1.20686@news7 .onvoy.net...[color=blue]
      > Nel wrote:
      >[color=green]
      > > Please can someone help me with this before I explode!!! (no pun[/color][/color]
      intended)[color=blue][color=green]
      > >
      > > $check = "Driving";
      > > $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color][/color]
      ½\',\.]{0,30}[ ])";[color=blue][color=green]
      > > preg_match($ss, $text,$check);
      > >
      > > $check = "driving"; // NOTE CHANGE Driving to driving
      > > $ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color][/color]
      ½\',\.]{0,30}[ ])";[color=blue][color=green]
      > > preg_match($ss, $text,$check);
      > >
      > > According to php.net /i is required to make it case sensitive, so why is
      > > this happening?!?![/color]
      >
      > Becuase you don't have it there???
      >
      > $ss = "`([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[
      > ])`i";
      >
      > --
      > Justin Koivisto - spam@koivi.com
      > http://www.koivi.com[/color]
      Thanks Justin.

      All the documentation says to use /i at the end of the string.


      I have spent ages trying to fit /i somewhere, anywhere to make it work.

      You may well have saved my sanity :-)

      Nel.


      Comment

      • Justin Koivisto

        #4
        Re: preg_match

        Nel wrote:
        [color=blue]
        > "Justin Koivisto" <spam@koivi.com > wrote in message
        > news:HjIXc.1092 $j1.20686@news7 .onvoy.net...
        >[color=green]
        >>Nel wrote:
        >>
        >>[color=darkred]
        >>>Please can someone help me with this before I explode!!! (no pun[/color][/color]
        >
        > intended)
        >[color=green][color=darkred]
        >>>$check = "Driving";
        >>>$ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color][/color]
        >
        > ½\',\.]{0,30}[ ])";
        >[color=green][color=darkred]
        >>>preg_match($ ss,$text,$check );
        >>>
        >>>$check = "driving"; // NOTE CHANGE Driving to driving
        >>>$ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color][/color]
        >
        > ½\',\.]{0,30}[ ])";
        >[color=green][color=darkred]
        >>>preg_match($ ss,$text,$check );
        >>>
        >>>According to php.net /i is required to make it case sensitive, so why is
        >>>this happening?!?![/color]
        >>
        >>Becuase you don't have it there???
        >>
        >>$ss = "`([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[
        >>])`i";
        >>[/color]
        >
        > Thanks Justin.
        >
        > All the documentation says to use /i at the end of the string.
        > http://php.us.themoes.org/manual/en/...preg-match.php
        >
        > I have spent ages trying to fit /i somewhere, anywhere to make it work.[/color]

        It's onlt /i if you use the "/" as the regex delimiter. In my reply, I
        used the backtick "`" instead (I do that so I don't have to escape all
        my "/" characters.

        Here's a little more reading (just search for perl regex or perl regular
        expressions to find a whole lot more!):

        Perl regex, regular expression, extracting information, text processing



        And the ones I'm sure you've found already:



        --
        Justin Koivisto - spam@koivi.com

        Comment

        • Nel

          #5
          Re: preg_match

          "Justin Koivisto" <spam@koivi.com > wrote in message
          news:pXJXc.1095 $j1.20677@news7 .onvoy.net...[color=blue]
          > Nel wrote:
          >[color=green]
          > > "Justin Koivisto" <spam@koivi.com > wrote in message
          > > news:HjIXc.1092 $j1.20686@news7 .onvoy.net...
          > >[color=darkred]
          > >>Nel wrote:
          > >>
          > >>
          > >>>Please can someone help me with this before I explode!!! (no pun[/color]
          > >
          > > intended)
          > >[color=darkred]
          > >>>$check = "Driving";
          > >>>$ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color]
          > >
          > > ½\',\.]{0,30}[ ])";
          > >[color=darkred]
          > >>>preg_match($ ss,$text,$check );
          > >>>
          > >>>$check = "driving"; // NOTE CHANGE Driving to driving
          > >>>$ss = "([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z[/color]
          > >
          > > ½\',\.]{0,30}[ ])";
          > >[color=darkred]
          > >>>preg_match($ ss,$text,$check );
          > >>>
          > >>>According to php.net /i is required to make it case sensitive, so why[/color][/color][/color]
          is[color=blue][color=green][color=darkred]
          > >>>this happening?!?!
          > >>
          > >>Becuase you don't have it there???
          > >>
          > >>$ss = "`([ ][0-9a-zA-Z ½\',\.]{0,30}".$check. "[0-9a-zA-Z ½\',\.]{0,30}[
          > >>])`i";
          > >>[/color]
          > >
          > > Thanks Justin.
          > >
          > > All the documentation says to use /i at the end of the string.
          > > http://php.us.themoes.org/manual/en/...preg-match.php
          > >
          > > I have spent ages trying to fit /i somewhere, anywhere to make it work.[/color]
          >
          > It's onlt /i if you use the "/" as the regex delimiter. In my reply, I
          > used the backtick "`" instead (I do that so I don't have to escape all
          > my "/" characters.
          >
          > Here's a little more reading (just search for perl regex or perl regular
          > expressions to find a whole lot more!):
          >
          > http://www.anaesthetist.com/mnm/perl/regex.htm
          > http://www.comp.leeds.ac.uk/Perl/matching.html
          >
          > And the ones I'm sure you've found already:
          > http://us2.php.net/manual/en/referen...ern.syntax.php
          > http://us2.php.net/manual/en/ref.pcre.php
          >
          > --
          > Justin Koivisto - spam@koivi.com
          > http://www.koivi.com[/color]

          Many thanks Justin :-))


          Comment

          Working...