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?
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.