regex - whole word match in javascript -


i using javascript in webpage. trying search single whole word through textbox. search: 'me' , should find 'me' in text, not find 'memmm' per say.

i using javascript's search('my regex expression') perform current search (with no success).

thank you!

edit: after several proposals use \b switches [which don't seem work] posting revised explanation of problem:

amm, reason doesn't seemt tricks. assume following javascript search text:

<script type='text/javascript'> var lookup = '\n\n\n\n\n\n2    pc games        \n\n\n\n'; lookup  = lookup.trim() ; alert(lookup );                 var tttt = 'tttt';                 alert((/\b(lookup)\b/g).test(2));  </script> 

moving lines essential

to use dynamic regular expression see updated code:

new regexp("\\b" + lookup + "\\b").test(textbox.value) 

your specific example backwards:

alert((/\b(2)\b/g).test(lookup)); 

regexpal

regex object


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -