jtified Posted August 27, 2009 Report Posted August 27, 2009 [/color] var patt1=new RegExp("e","g"); do { result=patt1.exec("The best things in life are free"); document.write(result); } while (result!=null) Quote
falkencreative Posted August 27, 2009 Report Posted August 27, 2009 Well, your code loops through the string. On the second to last loop, it finds an "e", so result isn't null. It then loops again, finds no "e"s, and generates a "null", which gets written out to the browser. Javascript isn't really my strong point, so there may be more elegant ways to do this, but this code would fix that issue, catching that final null: <br />var patt1=new RegExp("e","g");<br /><br />do<br />{<br /> result=patt1.exec("The best things in life are frees");<br /> if (result != null) document.write(result);<br />}<br />while (result!=null)<br /><br /> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.