Home > Web Front-end > JS Tutorial > Some small exercises on regular expressions

Some small exercises on regular expressions

php中世界最好的语言
Release: 2018-03-13 09:34:17
Original
2195 people have browsed it

这次给大家带来关于正则表达式的几个小练习,使用正则表达式的注意事项有哪些,下面就是实战案例,一起来看一下。

练习1:匹配abc

练习2:包含一个a~z,后面必须是0~9 -->[a-z][0-9]或者[a-z]\d
    * [a-z] : a~z
    * [0-9]/\d : 0~9

练习3:必须第一个是字母,第二个是数字 -->^[a-z][0-9]$
    * ^[a-z] : 表示首字母必须是a~z
    * \d{2,10} : 数字有2到10
    * [a-z]$ : 表示必须以a-z的字母结尾

练习4:必须第一个是字母,字母后面跟上4~9个数字

练习5:不能是数字0-9

    * [^0-9] : 不能是0~9练习6:QQ匹配:^[1-9]\d{4,11}$
都是数字5~12位
并且第一位不能是0练习7:手机号码匹配^1[3578]\d{9}$1.以13/15/17/182.长度是11
Copy after login

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

怎样添加带提示功能的代码块

常用的WebStorm快捷键


The above is the detailed content of Some small exercises on regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template