Q:

regex not fulfilling full condition

I am currently using regex to remove www. from any url entered into a text area. I ahve done this the following way:
var input = document.getElementById("tweet_text");
input.onkeyup = function() {
    input.value = input.value.replace(/www\.*/,"");
}

When a URL is copied and then pasted into the textarea, the regex does it's job.
If i was to manually enter a url it doesnt remove the .. I get to the last w and then the www gets removed allowing me to continue to type. Obviously the next character will be a . which will remain there, and end up with something like this:
http://.example.com

When it should look like this:
http://example.com

Any ideas on how to resolve this?

A:

That's happening because .* also matches an empty space (0 or more repetition). So, www\.* will successfully match www, and replace it. And then when you go on to type ., it won't match the pattern, and hence won't be replaced. 
Try using www\.+ or www\. instead:
input.value = input.value.replace(/www\.+/,"");

or:
input.value = input.value.replace(/www\./,"");

