Regular Expressions: Regular (regular) Expression
Regular expression search pattern is formed by a sequence of characters, and text can be used to replace text search
Common in string search and replace methods
var str = "Visit w3cschool";
var n = str.search(/w3cschool/i);
- / W3cschool: Search Field
- / I: case-insensitive
6 results
Regular expression modifiers:
- i: performing case-insensitive matching
- g: Perform global matching
- m: performing multi-line matching
Regular expression search characters in the range:
- [Abc]: Find any character between the brackets
- [0-9]: Find anything from 0-9
- [X | y]: to find any | options separated
Yuan characters:
- \ D: Digital
- \ S: Find a whitespace character
- \ B: matching a word boundary
- \ Uxxxx: Find the Unicode character specified in hexadecimal xxx
quantifier:
- n +: matches any string of at least one n
- n *: matches any string of 0 or more n
- n matches any ?: contains zero or a string of n
RegExp:
- In JavaScript, RegExp objects are predefined properties and methods of the regular expression object
test():
- A regular expression method, for detecting whether a string matching a pattern, and if so, returns true
exec():
- A regular expression method, being used to retrieve the string expression matching
- Returns an array, the array is stored is the result of a match, if not found, the return value is null
compile():
For changing the RegExp, search mode may be changed, or may be added to remove the second parameter