Results 1 to 3 of 3

Thread: using PCRE to replace everything between 2 words ungreedy.

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default using PCRE to replace everything between 2 words ungreedy.

    like the long title says. How do you use PCRE to replace everything between two words like "have" and "not" in the following

    $string = "the have and the havenots. Yet the haves are not there.";

    so that $string becomes

    "the s. Yet the there.";

    as always, this is not really important, but I am curious
    thanks.

    PS is this the right place for posting PCRE questions? It is sort of PHP and sort of not. Maybe I should post these questions in the 'Other scripting/ coding related discussions.' forum?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Good a forum as any... you'd do it like this:
    Code:
    $string = preg_replace('/have.*?not ?/', '', $string);
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Awesome, thanks for the info I was scanning google and just not finding the answer anywhere.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •