Regular expression _ regular expression for some digital validation

Source: Internet
Author: User
<= and? = and?: What do you mean by these three kinds of things, please explain them.
Your answer is very incisive, thank you.
Write a sample for you, written in JavaScript, you say the total number of left and right numbers does not exceed 20, plus "-" that is, the total length of the string does not exceed 21. As follows:
<script type= "Text/javascript" > var str = ' 111-3763232 '; var reg =/^ (? =.{ 3,21}$) \d+-\d+$/; Alert (Reg.test (str)); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

After the test will be able to meet your requirements.

What you want to ask is the following four look around structure. They do not match any specific characters and match only one position, just as "^" and "$" match the starting and ending positions of the strings.
(?=...) A positive look in the affirmative. Where "..." is a regular expression indicating that the character to the right of the current position must be matched by "...".
(?! ...) The positive negative look around. Indicates that the content to the right of the current position must not be matched by "...".
(<= ...) and (?<!...) The difference is the reverse positive look and reverse negative look, but the direction is left.

As for (?:), it is the same as the normal bracket () function, except that it does not store the child matches. In some cases, use (?:) Can improve the efficiency of regular expressions.

To say the expression "/^" (? =.{ 3,21}$) \d+-\d+$/":
^(?=. {3,21}$) sets the starting position of the string, followed by 3-21 arbitrary characters, followed by the end of the string.
\d+-\d+$ This is your question request, there is nothing to say.

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.