Home > Backend Development > PHP Tutorial > 韩顺平:正则表达式练习题

韩顺平:正则表达式练习题

PHP中文网
Release: 2023-02-28 11:22:02
Original
2310 people have browsed it

以下是韩顺平正则表达式练习题,希望对php中文网的同学们有帮助!

问题1匹配选项 gim 中对m的理解,  ^(\d)   u$

2Aaaddddjkkkkku

4ddddkkiieu

  在多段落模式下^ ,开头 结尾定位的影响

问题2说出一下匹配的结果:

/(\d){4}/gi  匹配  AAA1234kkkk

/1{3}/            1111 111  出现几次111           2

/1{3,4}/       1111 111  出现几次1111, 111   注意贪婪匹配 一次1111 一次111 

/1+/              1111 111  结果是                注意贪婪匹配  一次1111 111

/1*/              1111 111  结果是                 一次11111111

/1?/              空字符    结果是                出现空字符匹配成功

/a1*/             a111111   结果是                 a111111  注意*是修饰1

[abc]             abcd                           依次匹配到  a,b,c,d                         

/(han||)/                                       选择匹配符

问题3构造一下规则的正则表达式   ()叫做子表达式

abba  (\d)(\d)\2\1  注意\1不是(\d)   学会捕获子表达式与反向引用子表达式

形如aabbccdd         (\d)\1(\d)\2(\d)\3(\d)\4

5位为任意数-339911    (\d){5}-(\d)\2(\d)\3(\d)\4

综合:电子邮件格式

1.只有一个@

2.@前面是用户名,可以是0-9 a-z A-Z _字符

3.@后面是域名,可以是sohu.com tsinghua.org.cn并且域名只能是英文字母

/^[a-zA-Z0-9_-]+@([a-zA-Z0-9_-]+\.)+(com|cn|net|org)$/

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template