Hbulder installation and regular expression first met

Hbulider installation

Hbulider is mainly used to write html files, regular expressions are written in the js page,
Use this tool to help you learn regular expressions.
Hbulider's download URL is http://www.dcloud.io/#, click on the download button directly after entering, you can choose to install windows version and mac version
After the download is complete, register for free to use 

这里写图片描述 这里写图片描述 这里写图片描述 这里写图片描述 这里写图片描述 这里写图片描述

正则expression简介

1. Regular expression is an independent language, whether it is js, c language or java, the regular expressions inside are the same of,
Many programming languages ​​support string manipulation using regular expressions.
2. What is a regular expression?
A regular expression is a language used to describe or match a series of strings that conform to a grammar.
3. The use of regular expressions
Regular expressions are often used to retrieve, replace, or split textual content that conforms to a pattern, and can validate front-end data in a timely manner.
4. If you write a document, or watch a video on a platform to send some sensitive words, you will be prompted or filtered, or replaced with other characters, all done by regular expressions.
5. Application
Data validation, text replacement, content retrieval, filtering content
Can be understood as: the special matching, split, and replace functions that can not be completed by the string function 

小试牛刀

方式一:Create an object

Create a regular rule to match the string The regular rule is an object that comes out of new
The object comes with the method test method. Use this rule to find out if there is any in this string.
Responsible for the content of the rule 
    <body>

        <script type="text/javascript">

            // Create a regular rule 
            var  reg = new RegExp('lanou');
            var  str = 'www.lanou3g.com';
            // Use the regular rule to match the string 
            var result = reg.test(str);

            document.write(result);
        </script>

    </body>

这里写图片描述 这里写图片描述

方式二: By the literal

, there is no difference between the two methods, the result It is also consistent, no longer screenshot 
<body>

    <script type="text/javascript">

        // Create a regular rule can not be written as / 'lanoui' / Otherwise the quotes will also match 
        var  reg = /lanou/;
        var  str = 'www.lanou3g.com';
         / / use the regular rules to match the string 
        var result = reg.test(str);

        document.write(result);
    </script>

</body>

regular expression Atom

 atom is the smallest element in a regular expression, including English, punctuation, etc. \d matches any number \D with any number other than numbers A character match [^0-9]
\w matches any English letter, number or underscore [a-z0-9A-Z]
\W matches any character except letter, number or underscore [^a-z0-9A-Z]
\s| || matches any whitespace character   与任意一个空白字符匹配[\n\f\t\v]
\S matches any character except whitespace [^\n\f\r\t\v]Example:
Var reg = /\d\d\d/;
Match any three consecutive characters

Var reg = /b\d\d\d/
Match the three digits with the character b followed by the 

regular expression in the metacharacter

. Match any character except the space (newline) or match any character
\. Representative match "."
| Mainly used in the matching of illegal keywords, meaning or 

小试牛刀

<body>

    <script type="text/javascript">     
        var  reg = /六合彩|heroin|morphine|ice poison|killing|organization|; var  str = 'To make a fortune, come buy a lottery, kind of heroin, sell morphine, transport ice, kill murder ';// Use regular rules to match the string 
        var result = reg.test(str);
        if(result){
            document.write("?????");
        }else{
            document.write(str);
        }
    </script>

</body>

这里写图片描述 这里写图片描述

小牛牛刀

<body>

    <script type="text/javascript">     
        var  reg = /六合彩|heroin|morphine|ice poison|killing|organization/;var  str = ' want to make a fortune, come buy six 7-color, kind of sea pluin, sell? v, brown, wins poison, kills ';// Use regular rules to match strings
        var result = reg.test(str);
        if(result){
            document.write("?????");
        }else{
            document.write(str);
        }
    </script>   
</body>

这里写图片描述 这里写图片描述