Home > front end >  Adobe Dreamweaver JavaScript
Adobe Dreamweaver JavaScript

Time:09-20


JavaScript object summary
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Development tools and key technology: Adobe Dreamweaver JavaScript
Author: Peng Jinlin
Writing time: on April 28, 2020,
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Regular expressions: also known as the regular expression
English named Regular Expression, often abbreviated in the code for regex, RegExp or RE
Regular expressions are used to define some rules of the string, a computer can according to the regular expression, to check whether a string is conform to the rules, characters can conform to the rules are extracted from the content of the
Regular expressions are used for text matching tool, so this article mentioned many times in the search string/lookup, the meaning of this statement is in a given string, looking for matches the given regular expression, are likely to have more than one part of the string to satisfy the given regular expression, then each of these parts is called a match, the match in this article may have three kinds of meaning: one is to describe the part of speech, such as a string matching an expression; Is a kind of verbal, for example in the string matches a regular expression; Is there a noun, it is just said to "part of the string to meet the given regular expression",
Suppose you find hi in an English novel, you can use regular expressions, hi, this is the most simple regular expressions, which can exactly match the string that is composed of two characters, one character at a time before is h, one is after I, usually, deal with regular expression tool will provide an option to ignore case, if this option is selected, it can match the hi, hi, hi, hi this one of four kinds of circumstances,

Such as: the rules of the mobile phone number:
First of all, 13893443823 (11 digits)
1. Begin with 1
2. The second (3-9)
3. The third after any 9 Numbers
Grammar: var variable=new RegExp (" regular expression ", "match the pattern");
Use the typeof check regular object, will return to the object
Var reg=new RegExp (" a "); This expression can be used to check whether a string containing the characters in a
In the constructor can pass a matching model as the second parameter
I ignore case
G global matching
Var reg=new RegExp (" a "and" I ");
The method of the regular expression:
The test ()
- use this method can be used to check whether a string in accordance with the rules of the regular expression
If conform to return true, otherwise it returns false
2. Use the literal to create a regular expression
Grammar: var variable=/regular expression matching mode

- use literal method to create a simple
- use the constructor to create more flexible
Var reg=new RegExp (" a "and" I ");//use the constructor to create a regular expression
Var reg=/a/I;//create a regular expression, to check whether a string containing a or b or c
Reg=| a | b/c/;//use | said or the meaning of
The console. The log (reg. Test (" werwer "));
//create a regular expression, to check whether a string containing the letter
Reg=/a | b | | d | e | c/f;
[] to use the brace said range
[ABC] is equivalent to a | b | c reg=[ABC]/;
[a-z] means to match all lowercase reg=/[a-z];
[a-z] means to match all capital letters reg=/[a-z]/I;
[a-z] means to match all of the letters (with case)
[0-9] means to match all digital reg=/[0-9];
3. The string associated with a regular expression method
Support regular expression method of String object
1. The search () - retrieve values match the regular expression,
For example:
STR="hi, question, ihs, history";
Result=STR. Search (/hi/);
console.log(result);
2. The match () - find one or more of the regular expression match,
Represents the Regex class instances of a Match, can Match through the Regex instance () method returns a Match instance,
3. The replace () - replaced with regular expression matching substring,
4. The split () - a 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, - even if they don't specify global matching the method, will all split string
4. Macth ()
- can be according to the regular expression, from a string will be extracted from eligible content
- by default our macth content will only find the first to meet the requirements, find later stopped searching
We can set a regular expression to match global mode, so that it will match to the contents of all
Can set multiple matches for a regular expression pattern, and order, there is no
- the match () will match to the contents of the package to the returned in an array, even if only one result query to
For example:
STR="2234 234 sddfasdads SDFSD Hans";

Result=STR. Match (/[a-z]/ig);
console.log(result);

6. The replace ()
- strings can be specified in the replace with new content
- parameters description:
1. Be replaced content
2. New content
For example:
STR="hi, question, ihs, history";
Result=STR. Replace (/,/g, "^_^");
console.log(result);
4. The regular expression syntax (quantifier)
Create a regular expression to check if a string containing the aaa
Var reg=/aaa/;
The console. The log (reg. Test (" asdfsaaa "));
Quantifiers:
- through the quantifiers can set the number of occurrences of a content
- measure words in front of it only a content work
- {n} appear n
- {m, n} m times into n
- {n,} appear more than n
- appear at least once a +
- * a zero or zero or more times a
-? Once or zero
Check if a string with a
^ said the opening
$said the ending
5. Regular expression syntax (characters)
Check if a string contains ". "
1. ". "means to match any character
2. In the regular expression \ a backslash as the escape character
3. If you want to match characters ". "regular expressions for \.
4. The means to match a backslash \
Var reg=/./;//match any character
Reg=\./;//match ". "
The means to match any character
\ w match any letters, Numbers, "_" underline=="/A - z0-9 _
\ W matching in addition to letters, Numbers, "_" underline=="[^ A - z0-9 _]
\ d match Numbers [0-9]
\ D in addition to the number of [^ 0-9] any character
Matching \ s Spaces
\ S match any character except Spaces
\ b match word boundaries
\ B match the word boundaries,
Create a regular expression check summary a string containing the word hi
Reg=/\ bhi \ b/;
The console. The log (reg. Test (ihs, the history, the question, "hi"));
  • Related