Let's say a few gossip: I am a rookie programmer, belongs to benzo. I have been in front of the door for a long time, but I can't go. Discourage, depressed. This article is basically copying from helping documents. If you are not right, please give me a lot of advice, welcome to a lot of criticism. Ok, gossip less. Start. . . First, what is the regular expression? Why use regular expressions? You have written a section of the program when developing an HTML form that is often written to verify that a user fill in a certain format: it is long and stinky. For example: Verify that the value entered by the user is a qualified E-mail address, whether it is a suitable date, and more. If you have a regular expression, you will end his simple and accurate. In order to prove my statement, it will pick two programs in the CSND, and you will judge yourself: No regular expression: // function name: Chksafe // function introduction: Check if "'",' // ', "/" // Parameter Description: String // Return Value: 0: Yes 1: Not Function Chksafe (a) {fibdn = New Array ("'", "//", ", ",", ","; "," / "); I = fibdn.Length; j = a.length; for (ii = 0; II ; contains returning false, otherwise returns TRUE.
============================================================================================================================================================================================================= ================================|| /; Return! Reg.test (str);} ====================================== ================================================================================================================================================= ============================================================================================================================================================================================================= ==================== Know the regular expression! In fact, this is a simple app for regular expressions. More more powerful. So now, I will tell you that the regular expression can be used to do what: 1) Validity verification of data format: You have already seen it. 2) Text Replacement: Text Editor You should have more, which There is no search and replacement function? If you have used these, then, you are already the beneficiaries of regular expressions. 3) Extract strings: No, it is said that the search engine is not working. Oh, look at Microsoft Help An example of the document: For example, if you need to search the entire Web site to delete some excessive materials and replace some HTML formatted tags, you can use the regular expression to test each file, see if it is in this file. There is a material or HTML formatted tag that you want to find. Use this method to narrow the affected file range to those files that contain materials to be deleted or changed.
You can then use the regular expression to delete the outdated material, and finally, you can use the regular expression again to find and replace those markers that need to be replaced. Now I know what is regular expression. If you still don't know, then I finally found a more stupid than me! However, I still have to tell you a few more, let your Mind come upstairs: 1) Regular expressions are a text string processing (pattern verification, search replacement, etc.) for efficient, accurate, concise Methodology. 2) All mainstream programming languages provide support for regular expressions. Of course, the degree of implementation and implementation of each language are not the same, but basic thinking is the same. So, as long as you have a regular expression experience in a language, you should understand at other languages. (Also hurry out how your language is supporting regular expressions). 3) When applying regular expressions, be sure to add. If you don't add, someone will marry you behind you, although you can't hear it. 4) If you finish reading, you should use the cumbersome way to deal with the string, you should be more stupid than I. Haha. Second, in Java Script, the initial trial regular expression: Learning regular expressions are best starting from mode verification, because these things are more intuitive, easy to understand. For the simplest example, we must verify that a string is a postal code, how to verify it, first look at the program: / * * =================== ================================================================================================================================= ============================================= * / function ispostcode (str) {var rag = / ^ / D {6} $ /; // What kind of play, chaos, two-sided single quotes, double quotes are not! IF (reg.test (str)) {return true;} // end if // is simple: Return Reg.Test (STR); if the phrase is true. } // End function seeing that the past is still? This is the essence. Haha. He is used to verify that a string is a "mode" of a postal code. Where: /...: Represents the beginning and end of a pattern. ^: Used to match the beginning of the input string. (Locator) $: Used to match the end of the input string. (Locator) /: is a escape character, / d that matches a number.