# Replacing spaces in a string, the RegExp way

**URL:** <https://forum.kirupa.com/t/replacing-spaces-in-a-string-the-regexp-way/286515>\
**Category:** flash\
**Created:** [April 16, 2009, 3:06pm UTC](https://forum.kirupa.com/t/replacing-spaces-in-a-string-the-regexp-way/286515 "2009-04-16T15:06:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![greatbigbrain](https://avatars.discourse-cdn.com/v4/letter/g/3be4f8/32.png) [@greatbigbrain](https://forum.kirupa.com/u/greatbigbrain)\
**Post date:** [April 16, 2009, 3:06pm UTC](https://forum.kirupa.com/t/replacing-spaces-in-a-string-the-regexp-way/286515/1 "2009-04-16T15:06:10Z")

</div>

Hi Crew,  
So I’d like to remove all spaces from an input text box, and replace them with commas, and I’d like to learn how to do this with RegExp, which I’ve never before used.

This doesn’t work (though if I do s.search(re) it returns the first space):

```auto
var s:String = searchTerms.text;
var re:RegExp = /\s/g;
s.replace(re, ",");
trace(s);

```

Thanks for any help you can provide!
