Article positioning (target audience)
• People who have heard of regular expressions, have seen their use of the occasion, but have not mastered them skillfully
• At least once read the regular expression 30 minutes introductory tutorial but not fully mastered the person.
What is the regular expression
Regular expression (Regular Expression) is a concept, a grammatical, syntactic agreement. Each specific statement (C#,JAVA,JAVASCRIPT) has a specific implementation of the regular expression, and there is a difference. The regular expression 30-minute introductory tutorial is about a regular expression of. NET (C #).
JavaScript Regular Expressions
I am good at the regular expression of JavaScript, this regular expression is one of the biggest feature is not supported 0 width is reviewed after the assertion, the reason is very simple, JS is interpreted to perform. Details and so on to understand.
Syntax query
• Regular expression 30-minute introductory tutorial
JavaScript RegExp Object reference manual
Some of the methods in the JavaScript String object reference manual, such as Match,replace,search.
Application Scenarios
Regular expressions have two major scenarios of 1. Check whether the user's input is valid; 2. Extract some of the information you want from a bunch of information; the biggest difference between the two scenarios is that the validity of the detection input is for the entire input character, that is, to add ^ to match the start of the string and the $ to match the end of the string, otherwise it is not very meaningful, at least I have not encountered the situation without adding. And the scene that extracts the information generally involves the global search G
A simple example
Just look at the code, how can not grasp the regular expression, we have to practice: to open the chrome (if you have not installed chrome, you can not be regarded as the target reader), of course, installed Firebug Firefox or a high version of IE also OK, press F12, Pull up developer tools. Switch to the following tab and enter the code
/hello world/.test ("Hello World")
OK, the above code is to use a regular expression to detect whether a string contains "Hello World" this particular character. In JS, the most commonly used is the regexp of the direct volume, that is, in the two slash//, plus the syntax of the regular expression. That is, in the regular expression 30 minutes introductory tutorial to the syntax such as [Aeiou], \ (? 0\d{2}[)-]?\d{8}, and so on, placed in two slashes//as a JS regular expression object (/[aeiou]/,/\ (? 0\d{2}[)-]?\d{ 8}/), with the method mentioned in the JavaScript RegExp object reference Manual, can also be applied to some of the methods in the JavaScript String object reference manual to apply to actual programming, referring to the Hello World sample code above. Finally, according to my own experience, to do a practice, such as
1. Extract the contents of the body part of this article, or extract the text from all the hyperlinks
2. Design a form to verify user input, specific validation can refer to common regular expressions
Last Words
The above is my own learning regular expression of some experience, then the experience is: see a lot of grammatical details, but do not know how to put into practice, in their own a small practice, finally understand. to organize here.