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

    Join Date
    Nov 2005
    Posts
    227
    Rep Power
    16

    Combining these 2 REGEX into 1 nice one?


    Does anyone know if the following 2 regex can be joined into 1?

    Code:
    $string = preg_replace("/\* /","[^\s]*[[:>:]] ",$string);
    $string = preg_replace("/\*$/","[^\s]*",$string);
    The preg_replace turns the following strings...

    Code:
    hell*
    hell* world
    into...

    Code:
    hell[^\s]*
    hell[^\s]*[[:>:]] world
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,965
    Rep Power
    9397
    I don't think so - not without cheating.
    PHP Code:
    preg_replace("/\*( |$)/e""'[^\s]*' . ('$1' ? '[[:>:]] ' : '')"$string); 

IMN logo majestic logo threadwatch logo seochat tools logo