regular expressions

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

    regular expressions

    OK i have for example this string "hello my name is : yehuda hello my
    brother name is yehuda"

    Now I would like to split it in to array

    so if I'll just use this:

    preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);

    the function will use only the last yehuda as my splitter and keep the
    string/

    so how do i express string which shouldn't contain other string?



    thanks



  • Nicolas Bouthors

    #2
    Re: regular expressions

    Gandalf nous disait :
    preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);
    so how do i express string which shouldn't contain other string?
    Try to limit the action of your + with +? like this : /hello.+?yehuda/


    --
    Nicolas - 06 20 71 62 34 - http://nicolas.bouthors.org/album/

    Comment

    • Gandalf

      #3
      Re: regular expressions

      On Aug 17, 4:09 am, Russell Wood <bitbuc...@dyno de.netwrote:
      On 2008-08-16, Gandalf <goldn...@gmail .comwrote:
      >
      OK i have for example this string "hello my name is : yehuda hello my
      brother name is yehuda"
      >
      Now I would like to split it in to array
      >
      so if I'll just use this:
      >
      preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);
      >
      the function will use only the last yehuda as my splitter and keep the
      string/
      >
      so how do i express string which shouldn't contain other string?
      >
      If you want to split the string into an array at each space then use
      `explode':
      >
             http://au.php.net/manual/en/function.explode.php
      >
      --
      Russell Wood
      <http://www.dynode.net/~rjw/>
      ye I know explode but this is only an example my real code function
      need regular expression
      so is their something I can write instead of "." so a specific string
      wont be include?

      thanks!

      Comment

      • Russell Wood

        #4
        Re: regular expressions

        On 2008-08-16, Gandalf <goldnery@gmail .comwrote:
        OK i have for example this string "hello my name is : yehuda hello my
        brother name is yehuda"
        >
        Now I would like to split it in to array
        >
        so if I'll just use this:
        >
        preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);
        >
        the function will use only the last yehuda as my splitter and keep the
        string/
        >
        so how do i express string which shouldn't contain other string?
        If you want to split the string into an array at each space then use
        `explode':



        --
        Russell Wood
        <http://www.dynode.net/~rjw/>

        Comment

        • dmf

          #5
          Re: regular expressions

          On Aug 16, 10:31 pm, Gandalf <goldn...@gmail .comwrote:
          On Aug 17, 4:09 am, Russell Wood <bitbuc...@dyno de.netwrote:
          >
          >
          >
          On 2008-08-16, Gandalf <goldn...@gmail .comwrote:
          >
          OK i have for example this string "hello my name is : yehuda hello my
          brother name is yehuda"
          >
          Now I would like to split it in to array
          >
          so if I'll just use this:
          >
          preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);
          >
          the function will use only the last yehuda as my splitter and keep the
          string/
          >
          so how do i express string which shouldn't contain other string?
          >
          If you want to split the string into an array at each space then use
          `explode':
          >>
          --
          Russell Wood
          <http://www.dynode.net/~rjw/>
          >
          ye I know explode but this is only an example my real code function
          need regular expression
          so is their something I can write instead of "." so a specific string
          wont be include?
          >
          thanks!
          You may want to take a look at http://www.troubleshooters.com/codec...rl/perlreg.htm.
          It should give you a better understanding of regex's. You should find
          your answer here.

          Comment

          • Curtis

            #6
            Re: regular expressions

            Gandalf wrote:
            OK i have for example this string "hello my name is : yehuda hello my
            brother name is yehuda"
            >
            Now I would like to split it in to array
            >
            so if I'll just use this:
            >
            preg_match_all( "/hello.+yehuda/s", $data, $out, PREG_PATTERN_OR DER);
            >
            the function will use only the last yehuda as my splitter and keep the
            string/
            >
            so how do i express string which shouldn't contain other string?
            >
            >
            >
            thanks
            >
            >
            >
            I'm not sure I understand what you're trying to do, exactly. It sounds
            like you might want preg_split, though. If you could post an example
            of what you do want, it might help.

            --
            Curtis

            Comment

            Working...