PHP and Regex

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

    PHP and Regex

    Hello,

    if I extracted a string from a file ( ="test"; )
    How can I extract the word test from here. Sorry if this is not related to
    php (rather regular expression) but, I'll appreciate any help.




  • Sandman

    #2
    Re: PHP and Regex

    In article <WNGGg.17010$o2 7.12331@newssvr 21.news.prodigy .com>,
    "mark babli" <mbabli@photozi g.comwrote:
    Hello,
    >
    if I extracted a string from a file ( ="test"; )
    How can I extract the word test from here. Sorry if this is not related to
    php (rather regular expression) but, I'll appreciate any help.
    That's too general of a question. Do you want to extract alpha
    character found within the quotes, or can it look differently? To
    answer your question:


    #!/usr/bin/php
    <?
    $string = '( ="test"; )';
    preg_match("/\( =\"(\w+)\"; \)/", $string, $m);
    print $m[1];
    ?>

    Output: test

    --
    Sandman[.net]

    Comment

    • mark babli

      #3
      Re: PHP and Regex


      "Sandman" <mr@sandman.net wrote in message
      news:mr-80F777.20130122 082006@individu al.net...
      In article <WNGGg.17010$o2 7.12331@newssvr 21.news.prodigy .com>,
      "mark babli" <mbabli@photozi g.comwrote:
      >
      >Hello,
      >>
      > if I extracted a string from a file ( ="test"; )
      > How can I extract the word test from here. Sorry if this is not related
      >to
      >php (rather regular expression) but, I'll appreciate any help.
      >
      That's too general of a question. Do you want to extract alpha
      character found within the quotes, or can it look differently? To
      answer your question:
      >
      >
      #!/usr/bin/php
      <?
      $string = '( ="test"; )';
      preg_match("/\( =\"(\w+)\"; \)/", $string, $m);
      print $m[1];
      ?>
      >
      Output: test
      >
      --
      Sandman[.net]
      Actually, I need what is between the " ". Thanks


      Comment

      • Alvaro G. Vicario

        #4
        Re: PHP and Regex

        *** mark babli escribió/wrote (Tue, 22 Aug 2006 19:06:57 GMT):
        > $string = '( ="test"; )';
        > preg_match("/\( =\"(\w+)\"; \)/", $string, $m);
        > print $m[1];
        >?>
        >>
        >Output: test
        >>
        >--
        >Sandman[.net]
        >
        Actually, I need what is between the " ". Thanks
        Then it should be even easier:

        preg_match('/"(.*)"/U', $string, $m); // Not tested


        --
        -+ http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
        ++ Mi sitio sobre programación web: http://bits.demogracia.com
        +- Mi web de humor con rayos UVA: http://www.demogracia.com
        --

        Comment

        Working...