little help with this regular expression.

Discussion in 'PHP' started by ferdousx, Apr 1, 2009.

  1. #1
    I was trying to replace all occurance of character a space, followed by a letter or number and the na hash in my sentence with a simple hash. i am new to regular expression and i tried the following with preg_replace which didn't work:
    $sentence=preg_replace(' [0-9|a-z]#','#',$sentence);
    whats problem with that?
     
    ferdousx, Apr 1, 2009 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try:

    $sentence = preg_replace('/ [0-9a-z]#/', '#', $sentence);
    Code (markup):
    Note that it's case-sensitive by default. If you want to also match capital letters, you'll have to add A-Z in the square brackets, or tack i onto the very end of the pattern string.
     
    SmallPotatoes, Apr 1, 2009 IP