㈠RegExp objects
⑴JavaScript through built-in objects RegExp support regular expressions
There are two methods ⑵ RegExp object instantiated
① ② literal constructor
⑶ literal example
Example 1:
You will find only the first match result
Example 2:
By modifier g, matching full-text search, all is it is replaced
⑷ examples of constructors
(Ii) modifier
①g: global full text search, not add, search
②i: ignore case ignore case, the default case sensitive
③m: multiple lines multi-line search
Examples are as follows
(Iii) metacharacters
Regular expressions composed of two basic character types
⑴ literal text character : it represents the meaning of the word itself. For example: abc, 123
⑵ metacharacters : are expressions that have special meaning in being non-alphabetic characters. For example: *, + ,? , $, ^, |, \ , (), {}, []
(Iv) The character classes
⑴ Generally, a regular expression of characters in a character corresponding to the character
For example : The expression ab & \ t is the meaning of: a letter a plus b plus a letter a horizontal tab
⑵ We can use meta characters [] to build a simple class
⑶ so-called category refers to objects that meet certain characteristics, a general reference, rather than specific to a character
⑷ expression [abc] the character a or b or c classified as a class, expression can match such characters.
⑸ example :
★ negated character class
⑴ use meta characters ^ create a reverse class / negative category.
⑵ reverse class means not part of a class.
⑶ expression [^ abc] represents a content or not character b or c.
⑷ example:
(V) the scope of the class
⑴ regular expressions also offers a range of classes
⑵ so we can use [az] represents any character to connect two characters from a to z
⑶ This is a closed interval, and z is itself comprising a
⑷ For example:
⑸ in [] is the internal classes ligatures: [A-zA-the Z]
E.g:
⑸疑问:“-”并不是特殊字符也不是元字符,那我就想在类里面匹配横线,怎么办?
如下图所示:
•第一个例子:横线并未匹配
•第二个例子:如果横线在[0-9]里面,比如一个开头一个结尾里面,这种语法里面,就表示一个范围的意思,在后面加一个“-”就把所有的都匹配到了。