Javascript regular expression: \B |
<input type="button" value="Match1" onclick="javascript:demo('fred has a red car.');return false;" /> <input type="button" value="Match2" onclick="javascript:demo('The rat is here.');return false;" /> <input type="button" value="Match3" onclick="javascript:demo('100readers');return false;" /> <input type="button" value="Match4" onclick="javascript:demo('_readers');return false;" /> <br /><br /> <input type="button" value="No Match1" onclick="javascript:demo('The price is\treduced.');return false;" /> <input type="button" value="No Match2" onclick="javascript:demo('red is a color');return false;" /> <input type="button" value="No Match3" onclick="javascript:demo('Action:\nread\nwrite');return false;" /> <input type="button" value="No Match4" onclick="javascript:demo('Stop!read');return false;" /> <script type="text/javascript" language="JavaScript"> //<![CDATA[ function demo(text) { var re = /\Bre/; if (text.match(re)) { alert("match"); } else { alert("no match"); } } //]]> </script> |