1 / 10

正则表达式

正则表达式. 记录文本规则的代码,用于文本匹配 元字符 字符转义 重复 字符类和分组 反义. 基本元字符. .(小圆点) 匹配除换行符号外的任意字符 w 匹配字母、数字、下划线和汉字 s 匹配任意空白字符 d 匹配数字. 基本元字符. b 匹配单词的开始或结束 ^ 匹配字符串的开始,或排除 $ 匹配字符串的结束 以上都是单个字符匹配. 字符转义. 如果要求匹配元字符中的符号,则需要加反斜杠。例如+表示匹配加号 www.zjei.net 和 www.zjei.net. 字符重复. * 重复零次或多次 +

vail
Download Presentation

正则表达式

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 正则表达式 • 记录文本规则的代码,用于文本匹配 • 元字符 • 字符转义 • 重复 • 字符类和分组 • 反义

  2. 基本元字符 • .(小圆点) • 匹配除换行符号外的任意字符 • \w • 匹配字母、数字、下划线和汉字 • \s • 匹配任意空白字符 • \d • 匹配数字

  3. 基本元字符 • \b • 匹配单词的开始或结束 • ^ • 匹配字符串的开始,或排除 • $ • 匹配字符串的结束 • 以上都是单个字符匹配

  4. 字符转义 • 如果要求匹配元字符中的符号,则需要加反斜杠。例如\+表示匹配加号 • www.zjei.net和www\.zjei\.net

  5. 字符重复 • * • 重复零次或多次 • + • 重复一次或多次 • ? • 重复零次或一次

  6. 字符重复 • {n} • 重复n次 • {n,} • 至少重复n次 • {n,m} • 重复n到m次 • \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3} • ^w{3}\..+\.\w+$

  7. 字符类和分组 • [] • 表示匹配中括号中的任一字符 • () • 小括号内的为一个整体 • | • 前后两者任意匹配一种 • \(?0\d{2}[)-]?\d{8} • (\(0\d{2}\)\d{8})|(0\d{2}-\d{8})|0\d{2}\d{8}

  8. 反义 • \W:与\w相反 • \S:与\s相反 • \D:与\d相反 • \B:与\b相反 • [^something]:与[something]相反

  9. 一些正则表达式 • 0\d{2}-\d{8} • \b\w{6}\b • ^\w+ • <a[^>]+> • Windows98|Windows2000|WindosXP • ((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)

  10. 常见的正则表达式 • ^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$ • ^\+?[1-9][0-9]*$和^\-[1-9][]0-9“*$ • ^[A-Za-z]+$和^[A-Z]+$和^[a-z]+$ • ^[a-zA-Z]\w{5,15}$

More Related