Either modify the pattern beforehand so that it only matches the entire string:
var r = /^a$/
or check afterward whether the pattern matched the whole string:
function matchExact(r, str) {
var match = str.match(r);
return match && str === match[0];
}
More Related Contents:
- Regex – To allow numeric, only characters R, N, X, B, @ [closed]
- Regex for Email Address along with name format [duplicate]
- Negative lookbehind equivalent in JavaScript
- JavaScript regex multiline text between two tags
- Case insensitive regex in JavaScript
- Remove not alphanumeric characters from string
- I want to remove double quotes from a String
- Count number of matches of a regex in Javascript
- Replace a Regex capture group with uppercase in Javascript
- Regular Expression | Leap Years and More
- How to write regex to validate dates?
- Javascript Regex to replace text NOT in html attributes [duplicate]
- Match any non-word character (excluding diacritics)
- Finding Plus Sign in Regular Expression
- Combining regular expressions in Javascript
- Why does String.match( / \d*/ ) return an empty string?
- RegEx: How can I match all numbers greater than 49?
- How can I replace newlines/line breaks with spaces in javascript?
- How do I split a string by whitespace and ignoring leading and trailing whitespace into an array of words using a regular expression?
- Remove specific HTML tag with its content from javascript string
- In a regular expression, match one thing or another, or both
- Regex only capturing last instance of capture group in match
- (*SKIP)(*FAIL) workaround in JavaScript RegExp
- What is the need for caret (^) and dollar symbol ($) in regular expression?
- Javascript RegExp for splitting text into sentences and keeping the delimiter
- Commenting Regular Expressions
- How to insert space every 4 characters for IBAN registering?
- JavaScript Regex to match a URL in a field of text
- How can I use regex to get all the characters after a specific character, e.g. comma (“,”)
- Regex – Repeating Capturing Group