Reputation: 353
Is there any function in Javascript
that replicates Java's matcher.matches()
?
Ok, let me narrow it down.
JAVA: The matches function in java tries to match the input regex against an entire string, say the regex is "^http" and the string is "http://www.xxx.zzz", the output is false where as ^http.* returns true.
JAVASCRIPT: In js, the function i tried was ".test()" which returned true even when the regex is "^http" for the same input string.
I use java in server side and js in client side, and I want to express the same behaviour on both. Is there any other method in js that replicates the matches function in java
Upvotes: 1
Views: 1015
Reputation: 664936
The matches function in java tries to match the input regex against an entire string
There is no such function in JavaScript. You'll need to manually anchor your regex to the begin and end of the string.
/^http$/.test("http://www.xxx.zzz") // false
Upvotes: 3