#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2009
    Posts
    1
    Rep Power
    0

    Simple regex question


    Hi

    Please look @ the following

    $value = array("/-/","/between/","/and/");
    $wc = trim(preg_replace($value, substr($value[0],1,-1), $wc));

    lets say $wc is initialized with

    computers between 1000 and 2000

    it gets changed to

    computer - 1000 - 2000

    that is perfect.

    now lets say wc is

    shanandoah park

    it returns

    shen-oah park

    how can i get preg_replace to not replace 'and' in the
    second phrase yet keep the functionality of replacing 'and' in the first phrase?

    Thxs

    J
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,072
    Rep Power
    9398
    The \b metacharacter matches a word boundary...

    Comments on this post

    • prometheuzz agrees : Good hint!

IMN logo majestic logo threadwatch logo seochat tools logo