Use regular expressions to match the phone number

Use regular expressions to match the phone number

文献种类:专题技术文献;
开发工具与关键技术: VS              
作者:卢媛媛  ;
撰写时间:2019 年 3月 29 日 
  1. Regular expressions, also known as regular expressions, many programming languages ​​support regular expressions for string operations. For example, in Perl built on a powerful regular expression engine. Regular Expressions concept was originally developed by the Unix tools (such as sed and grep) of popularity. Regular expressions are usually abbreviated to "regex", the singular has regexp, regex, the complex has regexps, regexes, regexen.
  2. Related concepts: A regular expression is a logical formula of string operations, is to use some combination of a particular pre-defined characters, and these particular character, form a "string rule", this "rule string" is used a filter logic expression string.
  3. Given a regular expression and another string, we can achieve a certain purpose;
  4. Next, we use a regular phone number to match
  5. Here Insert Picture Description
  6. In the picture which we wrote a random phone number, and then declare a variable, then we further analyze regularization / 1 [3578] \ d { 9} / This string expression;
    Ø / 1 / is the first phone number digits ;
    Ø [3578] the second telephone number is not 1 and 2 as long as the two figures can, including all numbers in the [3578] array inside;
    Ø \ D is representative of the special characters of a regular expression {0-9} a number between
  7. We look at the results of the browser
  8. Here Insert Picture Description
  9. So we can further examine the other hand, if the first digit is the result of 2 rather than a return of
    10.Here Insert Picture Description
  10. Then the result is false
  11. Here Insert Picture Description
  12. So the regular expression is characteristic of flexibility, logic and functionality is very strong, you can quickly use a minimalist way to achieve complex control of the string;

II. I believe further encrypted phone number as a phone number contact information more widely, so beneficial to have disadvantages, in some things have registered to use the mobile phone number so some harassing phone information to let people upset
Here Insert Picture Description
is also variable above, plus Some virtual personal information, and then output the results in the console
Here Insert Picture Description
by console output we can see the phone number is encrypted * RegExp objects has become a regular expression to a new RegExp object, with the specified pattern and logo. If the argument is a regular expression pattern rather than a string, the RegExp () constructor will be used to create a new RegExp RegExp object with the same pattern and flags specified

Guess you like

Origin blog.csdn.net/qq_42577408/article/details/89053226