Javascript regular expression: search()


<input type="button" value="Match" onclick="javascript:demo('hi hello world.');return false;" />
&nbsp;&nbsp;&nbsp;
<input type="button" value="No Match" onclick="javascript:demo('hi world');return false;" />

<script type="text/javascript" language="JavaScript">
//<![CDATA[
   function demo(text) {
      var re = /\bhello\b/;
      var index = text.search(re);
      if (index > -1) {
         alert(index);
      } else {
         alert("no match");
      }
   }
//]]>
</script>