I want a regexp that allows common strings, such as abc, but also including the special characters ^ and $ at the start and the end of that string:
valid strings:
abc
^abc
^abc$
abc$
the abc regexp part is (I also admit little bit extra chars as numbers or hyphens):
regex = new RegExp("^([a-zA-Z0-9._-])+$");
which I can test with:
regex.test("a") // --> true
However, I am not being able to also admit the ^ and $ at the first and last character positions... How could I add them to the regex?
Note that adding them in the middle, should be invalid.
Example of invalids:
ab^c
ab$c
...