JavaScript regular expressions have 3 modifiers of/I,/m, and/g. /I is the most common, and best understood, case-insensitive representation of regular expression matches.
var regex =/abc/i;alert (Regex.test ("abc"));//true
/ m stands for multiline mode multiline, if the target string does not contain a newline character \ n, which is only one row, then the/M modifier has no meaning.
var multiline =/abc/m;var Singleline =/abc/;//destination string does not contain newline characters \nvar target = "abcabcabc";
The/ m modifier does not make any sense if the regular expression does not contain the beginning or end of a ^ or $ match string.
The regular expression does not contain ^ or $var multiline =/abc/m;var Singleline =/abc/;var target = "ABCAB\NCABC";
This means that the/ m modifier is only useful if the target string contains \ n and the regular expression contains ^ or $. If Multiline is false, "^" matches the starting position of the string, and "$" matches the end position of the string. If Multiline is true, then "^" matches the position of the beginning of the string and the location after "\ n" or "\ R", and "$" matches the position of the end of the string and the location before "\ n" or "\ r".
var mutiline =/^abc/m;var Singleline =/^abc/;var target = "EF\R\NABCD"; alert (Mutiline.test (target));//truealert ( Singleline.test (target));//false
\ r \ nyou represent line breaks under Windows, if only 1 \ n is the same effect. Because target is not a string that begins with ABC, the result of matching singleline is false, because target is a multiline string (containing \ n), and the 2nd line starts with ABC, so the match multiline result is true.
JavaScript Regular expression decoration appended multiline (/m) usage