Jump to content

About regExp


jtified

Recommended Posts

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 />


Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...