capture vs. non-capture
When grouping is not added:. Exec returns only the string that matches the current position var pattern=/[a-z]*\s\d{4}/; var str=‘google 2015‘; alert(pattern.exec(str));//google 2015
After the grouping is added, the grouped content is captured and assigned to the array returned by exec var pattern=/([a-z]*)\s(\d{4})/; var str=‘google 2015‘; alert(pattern.exec(str));//google 2015,goole,2015
Non-capturing or ungrouped grouping is captured(?:)
By adding a question mark and a colon before grouping, you can cancel capturing the group. var pattern=/([a-z]*)\s(?:\d{4})/; var str=‘google 2015‘; alert(pattern.exec(str));//google 2015,goole
Line break mode
var pattern= /\d+/g; var str= ' 1, abc\n2, EDF '; Alert (str.replace (Pattern,var pattern=/^\d+/g; var str= ' 1, abc\n2, EDF '; alert (Str.replace (Pattern,//matches the first var pattern=/^\D+/GM; Span class= "Hljs-keyword" >var str= ' 1, abc\n2, EDF '; alert (str.replace (Pattern,//exactly matches and replaces
When a newline character is present in a string, if we do not use anchor characters, it will match the global, including after line break.
However, because of the use of anchor characters, there is no way to match the result after a newline, even if the global is used, and you need to turn on line breaks at this point.