Home > front end >  Regular expressions
Regular expressions

Time:09-21

Regular expressions, a regular expression is used to match a string of character combinations of patterns, one can almost in all of the programming language and all computer platforms using the location of the processing tools, it can be used to find specific information, can also be used to find and edit or replace specific information,
Use the literal to create a regular expression, syntax:
Var variable=/regular expression matching mode using the literal method to create a more simple, use the constructor to create more flexible,
JavaScript strings and regular expressions of relevant methods:
Search () to retrieve the values match the regular expression, (whether can search string containing the specified content it may accept a regular expression as a parameter, then according to the regular expression to search string)
STR="hi, question, ihs, history";
Result=STR. Search (/hi/);
console.log(result);
Match () to find one or more of the regular expression match, (from a string will be eligible content extracted)
STR="2234 234 sddfasdads SDFSD Hans";
Result=STR. Match (/[a-z]/ig);
console.log(result);
The replace () to replace and regular expression matching substring, (string can be specified in the replace with new content)
STR="hi, question, ihs, history";
Result=STR. Replace (/,/g, "^_^");
console.log(result);
Split () string into an array of strings, (string into an array of strings, this method can pass a regular expression as a parameter, this method will be based on regular expressions to split,)
Var STR="1 h3h5h6u6n8b6f5a4n5n6";
Var result=STR. The split (/[a-z]/I).
console.log(result);
Regular expression syntax (quantifier)
Through the quantifiers can set the number of occurrences of a content, quantifier in front of it only a content,
  • Related