Am I missing something in basic node.js regular expression syntax?
It doesn't matter if I start with ^ or end with $, what I missing in the regex syntax to get these outputs:
var Regex = require("regex");
//var Regex = require("regexp"); //performs the same with both
var regex = new Regex(/(a|b)*abb/);
console.log("The pattern matches: " + regex.test("abb")); // true
//Match a decimal number in sqaure brackets
var regex1 = new Regex(/\d/);
console.log("The pattern matches: " + regex1.test("9"));
var regex2 = new Regex(/^\d$/);
console.log("The pattern matches: " + regex2.test("9"));
var regex3 = new Regex(/^\d$/);
console.log("The pattern matches: " + regex3.test("9"));
var regex4 = new Regex(/^\[\d\.\d\]$/);
console.log("The pattern matches: " + regex4.test("[9.9]"));
var regex5 = new Regex(/^\[[0-9]\.[0-9]\]$/);
console.log("The pattern matches: " +regex5.test("[9.9]"));
output:
C:\nodeapps\CSV IO>node regexTest.js
The pattern matches: true
The pattern matches: false
The pattern matches: false
The pattern matches: false
The pattern matches: false
The pattern matches: false
Am I syntactically not seeing something?
require("regex")new Regex(...). Use plain regex literals.var regex1 = /\d/;should work.