How do I break out of a series of string replace( )?
<p>I have a collection of short strings in the form [a][z] where a and z are (component) substrings. The strings that can go in [z] are limited to about 100, and only one of them can appear in the whole input string.</p>

<p>Now, I need to replace the [z] string into another string. Given the data format, as soon as I find a match, I know I can stop looking. I want to return the replaced string.</p>

<p>My approach is suboptimal because I loop through all possibilities before returning the modified string. I'd like to know if there's a way to break the search, possibly using the fact that the input string is changed when there's a match? How can I tell that the replacement happened? I need to run this function about 1000 times per page load so I think that any improvement will be noticed. Thanks in advance!</p>

<p><a href="http://jsfiddle.net/MsWAZ/3/" rel="nofollow">http://jsfiddle.net/MsWAZ/3/</a></p>

<pre><code>function replaceEnd(input) {
        // bb, cc, and d are what I call [z]
        input = input.replace("bb", "Bob");
        input = input.replace("ccc", "Carl");
        input = input.replace("d", "Dave");

        return input;
}

document.write(replaceEnd("aabb") + "&lt;br&gt;");
document.write(replaceEnd("eaccc") + "&lt;br&gt;");
document.write(replaceEnd("uoid") + "&lt;br&gt;");
</code></pre>

<p>Outputs:</p>

<pre><code>aaBob
eaCarl
uoiDave
</code></pre>
