To use a dynamic regular expression see my updated code:
new RegExp("\\b" + lookup + "\\b").test(textbox.value)
Your specific example is backwards:
alert((/\b(2)\b/g).test(lookup));
More Related Contents:
- javascript regex
- How can I use Unicode-aware regular expressions in JavaScript?
- Regex to get string between curly braces
- Validate phone number with JavaScript
- What is the meaning of the ‘g’ flag in regular expressions?
- What is the difference between RegExp’s exec() function and String’s match() function?
- Is there a version of JavaScript’s String.indexOf() that allows for regular expressions?
- split string only on first instance of specified character
- Remove HTML Tags in Javascript with Regex
- Remove whitespace and line breaks between HTML elements using jQuery
- How to replace last occurrence of characters in a string using javascript
- Validating user’s UTF-8 name in Javascript
- regular expression to match exactly 5 digits
- Syntax error in IE using ES6 arrow functions
- Javascript regular expression to validate URL
- Split a string by whitespace, keeping quoted segments, allowing escaped quotes
- How to wrap part of a text in a node with JavaScript
- Increment a number in a string in with regex
- Insert dash after every 4th character in input
- Insert space before capital letters
- how to use dotall flag for regex.exec()
- regular expression for finding decimal/float numbers?
- regex pattern to match the end of a string
- How to remove square brackets in string using regex?
- Regular expression with the cyrillic alphabet
- Regular expression for only characters a-z, A-Z
- Regex for checking that at least 3 of 4 different character groups exist
- Get filename from string path in javascript?
- How to use a regular expression in querySelectorAll?
- How to replace non-printable unicode characters (Javascript)