Are javascript and java regular expression the same? Can we use the same regular expression at both places to validate both on server side client?
-
Regex is regex. Should work the same way. :)Debosmit Ray– Debosmit Ray2016-02-23 07:20:11 +00:00Commented Feb 23, 2016 at 7:20
-
can you share some scenarios so that we can give hints. its too broad to answer.Vikash Pandey– Vikash Pandey2016-02-23 07:21:47 +00:00Commented Feb 23, 2016 at 7:21
-
1Possible duplicate of Differences in regex patterns between JavaScript and Java?user2705585– user27055852016-02-23 07:21:58 +00:00Commented Feb 23, 2016 at 7:21
1 Answer
Is javascript and java regular expression are same ?
They're very similar, but they're not the same, as a brief glance at reference material makes clear, say MDN's article on JavaScript regular expressions vs. Java's Pattern class documentation. For one thing, Java's regex supports various Posix character classes which JavaScript regrettably does not.
Can we use same regular expression at both place to validate server side validation and client side validation ????
That's actually a different question, because you can run JavaScript on the JVM, so you can use the exact same expression in your client-side JavaScript code and your server-side code running on the JVM, using Rhino or Nashorn, which are JavaScript scripting engines for the JVM. You can compile JavaScript code to Java bytecode and use it like a Java class.