Article positioning (target readers)
• People who have heard of regular expressions and used them but are not familiar with them]
• People who have read Regular Expressions for at least 30 minutes getting started, but are not fully familiar with them.
What is a regular expression?
Regular Expression is a concept and a syntax and syntax convention. Each specific statement (C #, Java, and JavaScript) has a specific implementation of a regular expression, and there are differences. The getting started with regular expressions in 30 minutes is about regular expressions of. net (C.
Regular Expressions in JavaScript
I am good at JavaScript Regular Expressions. One of the biggest features of this regular expression is that it does not support the assertion after the blank-width positive review. The reason is very simple. js is interpreted and executed. The details will be further understood.
Syntax Query
• Getting started with regular expressions in 30 minutes
• JavaScript RegExp Object Reference Manual
• Some methods in the JavaScript String Object Reference Manual, such as match, replace, and search.
Application scenarios
Regular expressions have two application scenarios: 1. checks whether user input is valid. 2. extract part of the information you want from a heap of information. The biggest difference between the two scenarios is that the validity of the input is for the entire input character, that is, add ^ to match the start of the string and $ to match the end of the string. Otherwise, it is of little significance. At least I have not encountered any additional scenes. However, information extraction generally involves global search g
Simple Example
I can't grasp the regular expression just by looking at the code. Let's take a look at it: Open chrome (if you haven't installed chrome, you can't be the target reader of this Article ), of course, firefox or later IE installed with firebug is also OK. Press F12 to call up the developer tool. Switch to the following tab and enter the code
/Hello World/. test ("Hello World ")
OK. The above Code uses a regular expression to check whether a string contains a specific character "Hello World. In JS, the most commonly used is the direct amount of Regexp, that is, adding the regular expression syntax to two slashes. That is to say, in the regular expression 30-minute getting started tutorial, the mentioned syntaxes include [aeiou], \ (? 0 \ d {2} [)-]? \ D {8} and so on. Put it in two slashes // to become a JS Regular Expression object (/[aeiou] //,/\ (? 0 \ d {2} [)-]? \ D {8}/), which has the methods mentioned in the JavaScript RegExp object reference manual and can be applied to some methods in the JavaScript String object reference manual before being applied to actual programming, for more information, see the preceding Hello World sample code. Finally, based on my own experience, we need to do a practice on our own, such
1. Extract the body content in this article, or extract all the text in the hyperjoin.
2. Design a form to verify user input. For details, refer to common regular expressions.
Last words
The above is my experience in learning regular expressions. At that time, I realized that I saw a lot of syntax details, but I didn't know how to put them into practice. After I had a small practice, finally understand. Sort it here.