Thread: Using regex
View Single Post
Old 07-20-2009, 03:14 PM   #5 (permalink)
benton
The Contributor
 
Join Date: Apr 2008
Posts: 78
Thanks: 0
benton is on a distinguished road
Default

Thanks for the suggestions but they don't seem to be working. I changed the input string to more properly illustrate the problem. So given this string
PHP Code:
$str '#!$abstract modern-fields'
it should output
Quote:
abstract modern-fields
If I use this
PHP Code:
echo ereg_replace("[^[:alpha:],[:digit:],_,[:blank:]]","",$str).'<br>'
It displays
Quote:
abstract modernfields
And if I use this
PHP Code:
ereg_replace("[[!-@],[:punct:]]","",$str).'<br>'
It displays
Quote:
#!$abstract modern-fields
The #!S are all listed as characters in :punct: so those should be stripped. The first method does that but it also removes the hyphen. The second doesn't remove the punctuation but handles the hyphen correctly. Would someone point out my mistake, please?
benton is offline  
Reply With Quote