# Slugify a string in JavaScript

> Learn how to slugify a string in JavaScript using the slugify library, and how to strip dots and other punctuation with its remove regex option.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-01-09 | Topics: [JavaScript](https://flaviocopes.com/tags/js/) | Canonical: https://flaviocopes.com/slugify-a-string-in-javascript/

Install the `slugify` library

```javascript
npm i slugify
```

Then import it

```javascript
import slugify from 'slugify'
```

and you can do

```javascript
const slug = slugify('Testing this')
console.log(slug) //testing-this
```

Note that if the string contains dots or other punctuation, it will not strip that.

To remove that, you can use a regex like this:

```javascript
slugify('Testing. this!', { remove: /[*+~.,()'"!:@]/g })
```

If you just need to slugify a string once, without writing any code, use my [slug generator tool](https://flaviocopes.com/tools/slug-generator/).
