I’m new to regular expressions.
The following code works as expected, printing first “true” and then “false”, the backslash in front of the period escaping it:
var pattern = new RegExp(/\./);
document.write(pattern.test("."));
document.write(pattern.test("a"));
But why does the following print “false”:
var pattern = new RegExp(/\b\./);
document.write(pattern.test("."));
The period is, after all, at the beginning of the string.
You want to try using
^–If you have
it matches the
.‘s inHello. How are you.