We can use:

^: match the beginning
$: match the end

 

Let's say we have the string like the following:

var str = `12/1/16
12-16-13
11/12/16
12-12-2016`;

 

What we want to do is get all the '12' which at the begining of each line:

If we do like that:

var regex = /^12/g;

[Regular Expressions] Match the Start and End of a Line_Regular

 

To solve this problem, we can use 'm' flag:

var regex = /^12/gm;

[Regular Expressions] Match the Start and End of a Line_Regular_02

 

And also we want to get the line which end by '16':

var regex = /^12.+16$/gm;

[Regular Expressions] Match the Start and End of a Line_Regular_03