# Remove all non-alphanumerical characters except dashes

**URL:** <https://forum.kirupa.com/t/remove-all-non-alphanumerical-characters-except-dashes/282202>\
**Category:** Uncategorized\
**Created:** [February 18, 2009, 10:58pm UTC](https://forum.kirupa.com/t/remove-all-non-alphanumerical-characters-except-dashes/282202 "2009-02-18T22:58:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imagined](https://avatars.discourse-cdn.com/v4/letter/i/a87d85/32.png) [@imagined](https://forum.kirupa.com/u/imagined)\
**Post date:** [February 18, 2009, 10:58pm UTC](https://forum.kirupa.com/t/remove-all-non-alphanumerical-characters-except-dashes/282202/1 "2009-02-18T22:58:15Z")

</div>

I have this to replace spaces with dashes which works just fine

```php
$stripped_string = str_replace(' ', '-', $string_to_be_stripped);

```

Now I want to remove all non-alphanumerical characters except the dashes. I have this, but it also removes the dashes:

```php
$stripped_string = ereg_replace('[^A-Za-z0-9]', '', $string_to_be_stripped);

```

I also tried [^A-Za-z0-9\_-]’ but it doesn’t work. I’m not that good with regular expressions.

Any help on removing all non-alphanumerical characters except dashes?
