var re = new RegExp("/\b"+test+"\b/");
\b
in a string literal is a backspace character. When putting a regex in a string literal you need one more round of escaping:
var re = new RegExp("\\b"+test+"\\b");
(You also don’t need the //
in this context.)
More Related Contents:
- Find list of strings that matches a pattern that start with a special character « and end with a special character »
- Remove text between two parenthesis, if two more parenthesis [closed]
- How to replace plain URLs with links?
- Regular expression to get a string between two strings in Javascript
- Regex to get string between curly braces
- Validate phone number with JavaScript
- Detect URLs in text with JavaScript
- Regular Expression to get a string between parentheses in 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?
- Remove HTML Tags in Javascript with Regex
- Remove whitespace and line breaks between HTML elements using jQuery
- Remove HTML comments with Regex, in Javascript
- escaping question mark in regex javascript
- Javascript regex (negative) lookbehind not working in firefox
- JavaScript/regex: Remove text between parentheses
- JavaScript Regex, where to use escape characters?
- javascript regex for password containing at least 8 characters, 1 number, 1 upper and 1 lowercase [duplicate]
- JavaScript Regular Expression Email Validation [duplicate]
- Extract image src from a string
- How to prevent invalid characters from being typed into input fields
- How to convert “camelCase” to “Camel Case”?
- Regex for parsing single key: values out of JSON in Javascript
- What’s the correct regex range for javascript’s regexes to match all the non word characters in any script?
- javascript split string by space, but ignore space in quotes (notice not to split by the colon too)
- Mask US phone number string with JavaScript
- Convert string to Pascal Case (aka UpperCamelCase) in Javascript
- Regex – Repeating Capturing Group
- How do you split a javascript string by spaces and punctuation?