Regular expressions with Javascript
-
I've done a lot of server-side regular expressions (including with .NET), but when it comes to Javascript regular expressions, they don't seem to follow the same rules. I've narrowed down a current issue to be that the Javascript Regular expression evaluator doesn't interpret '\d' to mean a digit, so I made a quick fix by simply inserting in '[0123456789]' instead, which fixed the issue. Am I doing something incredibly dumb, or is the standard for regular expressions in Javascript actually different?
-
I've done a lot of server-side regular expressions (including with .NET), but when it comes to Javascript regular expressions, they don't seem to follow the same rules. I've narrowed down a current issue to be that the Javascript Regular expression evaluator doesn't interpret '\d' to mean a digit, so I made a quick fix by simply inserting in '[0123456789]' instead, which fixed the issue. Am I doing something incredibly dumb, or is the standard for regular expressions in Javascript actually different?
There are some differences, although you can force .NET's Regex engine into Javascript compatibility by using the ECMAScript option: ECMAScript vs. Canonical Matching Behavior[^] Here's a tool you might find helpful: http://www.cuneytyilmaz.com/prog/jrx/#[^] If you have questions on the behavior of a specific expression, post the expression along with enough target text to reproduce the behavior you are concerned about.
----
You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.