I'm writing a script to change all the urls of my content over to a new place.

```
var regex = /.*cloudfront.net/
var pDistro = "newDistro.cloudfront.net/"

for(var i=0;i<strings.length;i++){
    strings[i] = strings[i].replace(regex,pDistro);
}

```

The strings I'm doing `replace` on average about 140 characters each. They're urls that follow the format: `https://[thing to replace].cloudfront.net/[something]/[something]/[something]`

But this operation is terribly slow, taking about 4.5 seconds to process an average-sized array.

Why is this so slow? How can I make this faster?

If this question would be better suited to the codereview stack exchange, or some other site, let me know and I'll move it there.

EDIT:
-----

The data, as it appeared in the db I was pulling from appeared to be 140 characters. During the pull process, some virtualization happened and appended 400 more characters onto the string, so no wonder the regex takes so long.

The 140-character-string loop takes considerably less time, as others have pointed out.

The moral of the story: "Make sure the data you have is what you expect it to be" and "If your regex is taking too long, use smaller strings and a more specific regex (i.e. no wildcard)"