Hi All

I am trying to query a string - i.e. "the system is still running and we have no problems"

but i want to "cut" the string so it ends after running.

so i end up with the "system is still running"

how can i do this using regular expressions? i am coding in PHP and am importing data in through a file into a variable. there is only 1 instance of the word running in the whole document, i just need to find it, and delete EVERYTHING after that word!

Any ideas????

Greatly appreciated!!

    Untested:

    $output = preg_replace('/(?<=running)\b.*/', '', $input);
    

      Hi NogDog

      Thanks for the quick reply!!!

      your command works! but only for a single line. so basically it only deletes eveyrthing after Running on that line. Anything that is on a new line below it doesnt get deleted. i.e if i change the word Running for Never in your code, the output below shows

      5555 Never

      more specifically i am trying to do the following:

      5555 Never Running
      5556 2:10PM

      5557 3:10PM

      I want to basically put the number 5555 into a variable. So I want to delete everything after the word Running - that goes on new lines too..... Actually i want to delete the word Never and everything after the word Never. then i will be just left with the 5555 number.

      I can manipulate the first line no problems, but i am having trouble working with the subsequent lines. Everything i do doesnt effect them! Hence i need to delete Everything after the word Running.

      Thx!!!

        This little modification should get rid of everything after "running" (plus make it case-insensitive):

        $output = preg_replace('/(?<=running)\b.*/[color=red]is[/color]', '', $input);
        

          AWESOME!!!! worked Pefectly!! Your help is greatly appreciated!!!!!

          I just have a question regarding hte solution, i was wondeirng if you could explain a section of it, as i am still kind of new to the regular expresison stuff.

          the part i do not really understand is the following chunk

          '/(?<=running)\b.*/is'

          i dont quite understand what is happening within the quotes.

          Also, 1other question. My output returns a carriage return and then my id. is there anyway to remove a carriage return from before my 5555?

          so if a file started here


          5555

          this is what is shown - there is a extra line above my id which i would also like to remove.

          Once again NogDog I really really appreciate the help!

            '/(?<=running)\b.*/is':
            
            /        start of pattern
            (?<=     begin look-behind assertion
            running  look-behind assertion pattern
            )        end look-behind assertion
            \b       word boundary
            .        any character
            *        0 - n occurences of preceding character
            /        end of pattern (modifiers follow)
            i        case-insensitive matching
            s        include newlines as matching a "." wildcard character
            

            The easy way to clean up your final value would be to use trim().

              got exactly what i needed!

              Appreciate the help 🙂

                Got an added twist to this problem now...

                my output is the following:

                44444 6:31:00 PM, 10/18/2006
                55555

                now what i want to do is i just need 55555 but this number can change....so its not a fixed value, but it is 5 digits.

                I basically now need to delete everything before 55555

                is there a way to delete everything above theline you are working with?????

                thxxxxxx!!!!!!!!!

                  Perhaps:

                  $result = substr($string, -5);
                  

                  ?

                    Hi NogDog

                    That seems to delete everything leaving me with a blank variable 😕

                    played around with it a little more... think i got it to work. I migh have had some white space that caused it to delete EVERYTHING :queasy:

                    lol once again your help was and is greatly appreciated!!!

                    you by any chnace use msn/aim? lol nice ot have good ppl that you can contact at a notice 🙂

                    Cheers!!

                      2 months later

                      NogDog, This is working great for me. Except it would be great if it could find a string.

                      'The follow message is ..... ' I have a couple of general statements that I'd like to remove....the usually 'this is a personal message do not forward', safe harbor warnings, company advertisments. Can you help me convert 'running' it to a string. I'm getting errors trying to plug the string in or load to a $ variable.

                      Thanks

                        Write a Reply...