Javascript Regular var re = new RegExp (pattern, flag); replace each group with a specific value for the second, or use the RegExp function. replace (//, fn); verify whether RegExp is true. test (); used to test true false RegExp.exe c (); the array returned by the Group first returns a total group and then returns each group alert(re.exe c (o) [1]); 0: returns the total set. 1: returns the First Matching. 2: returns the second string. There is also a match method. The match () method can be used to retrieve the specified value within the string, or find a match between one or more regular expressions. This method is similar to indexOf () and lastIndexOf (), but it returns the specified value rather than the position of the string. If regexp does not mark g, the match () method can only perform one match in stringObject. If no matching text is found, match () returns null. Otherwise, it returns an array containing information related to the matched text it finds. The 0th elements in the array store the matching text, while the remaining elements store the text that matches the regular expression's subexpression. In addition to these regular array elements, the returned array also contains two object attributes. The index attribute declares the position of the starting character of the matching text in the stringObject, And the input attribute declares the reference to the stringObject. If regexp has a flag, the match () method performs a global search and finds all matching substrings in stringObject. If no matched substring is found, null is returned. If one or more matched substrings are found, an array is returned. However, the content of the array returned by global match is very different from that returned by the former. Its array elements store all matched substrings in stringObject, and there is no index or input attribute. Note: In global search mode, match () does not provide text information that matches the subexpression, nor declare the position of each matched substring. You can use RegExp.exe c () to retrieve global information (). [Javascript] view plaincopyvar str = "abcd"; alert (str. match (/(abc) d/); returns an array abcd, if abc wanring does not match globally, the regular expression will match only one place by default. The flag is ignored. The case-insensitive g match is all equivalent to the php preg_match_allm match multiline. * add? .*? Is to prohibit greedy character ^ string start position $ string end position \ s matching space \ S matching non-blank character [] indicates the range of [a-z] special characters only, []-none of them are special characters. \ w matches letters and numbers, and _ \ W matches non-letters and numbers, and _ \ d matches numbers? Repeat 0 times or 1 time \ D to match non-digit _ the same as [^ 0-9. match any character except linefeed * match 0 or more + match one or more () groups (a (B (c) group nesting (abc) (bc) (c )(? :) Non-capturing group is a group, but exec does not capture {n,} repeat n times or multiple times {n} repeat n here {n, m} repeats n to m times | or? = Forward looking forward ?! Negative foresight +? * {} Can all be followed? To prohibit greed, you need to add two escape characters to the string. the decimal point must be followed by a slash because the regular expression syntax contains a decimal point ([{^ $ | )? * + You can also use the regular expression var o = "----- 35435435 --"; alert (o. replace (/-+/, '#'); replace all-replace spaces on both sides var s = o. replace (/^ \ s + /,''). replace (/\ s + $/, ''); function trim (s) {var re =/^ \ s *(. + ?) \ S * $/; return re.exe c (s) [1];} converts the string of the specified rule to an array split (); search for the location where the specified string appears. search (the string to be matched) indexOf (the string to be matched, start position) The RegExp attribute re. source returns the regular expression re. lastIndex returns the subscript re. lastParen returns the static group attribute RegExp of the last query. input gets the RegExp string to be matched. leftContext obtains the regExp before matching data. regExp of the matching data obtained by rightContext. $1 ~~~ $9 returns the content of the group RegExp from 1 to 9. multiline = true enable multiline replace multiline content use gvar s = "1. ABC \ n2.DEV "; var rel =/^ \ d \. /mg; alert (s. replace (rel ,''));