The regular expression of the beef Brisket JavaScript (ii)

Source: Internet
Author: User

Following the basics of JavaScript in the last article, let me say something about JavaScript regular expressions today.

The first thing to ask is, what is a regular expression, what can a regular expression do?

Regular Expressions: A regular expression is a text pattern consisting of ordinary characters (such as characters A through Z) and special characters (called metacharacters). This pattern describes one or more strings to match when looking up a text body.
A regular expression, as a template, matches a character pattern to the string you are searching for.

Function: Tests a pattern of a string. For example, you can test an input string to see if there is a phone number pattern or a credit card number pattern in the string. This is called data validation replacement text. You can use a regular expression in your document to identify specific text, and then you can either delete it all or replace it with another text, and extract a substring from a string based on pattern matching. Can be used to find specific text in text or input fields.

Well, the definition is always abstract, and to get a deeper understanding of regular expressions I recommend a Web site: regular expressions in JavaScript. Let me give you a small example for your reference.

? Indicates that only one character or no character (0,1) can be entered;

<script language= "javascript" type= "Text/javascript" >var reg =/ab?c/g;var str = "ABC abbc adbc AC"; var found = str. Match (reg); alert (found);</script>
You can guess the input results, such as:

+ indicates that more than one character is entered, including one character. (1, ....... );

<script language= "javascript" type= "Text/javascript" >var reg =/ab+c/g;var str = "ABC abbc adbc AC"; var found = str. Match (reg); alert (found);</script>
input Result:

* indicates that more than 0 characters are entered, including 0. (0, ....... )

<script language= "javascript" type= "Text/javascript" >var reg =/ab*c/g;var str = "ABC abbc adbc AC"; var found = str. Match (reg); alert (found);</script>
Output Result:

Again, the regular expression in the content of more, we need to practice, do a good job of summing up, are some practical examples, very important. For example, our phone number to limit the number of input digits, in office to find the replacement function and so on are used to use regular expression application, I hope you have the flexibility to master.

Each time the summary is a distillation of knowledge, in the thinking of the knowledge to consolidate, do a good job of daily summary, let the knowledge freeze.

If you have any comments and suggestions, actively shoot bricks oh.


The regular expression of the beef Brisket JavaScript (ii)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.