Regular Expression与Java.pptVIP

  • 2
  • 0
  • 约1.53万字
  • 约 50页
  • 2016-12-31 发布于江西
  • 举报
Regular Expression与Java.ppt

Regular Expression與Java 蕭宇程 swanky.hsiao@ / Introduction to Regular Expressions Regular Expression Syntax Object Models Using regexes in Java Part 1: Introduction to Regular Expressions Regular expressions are the key to powerful, flexible, and efficient text processing. Searching Text Files: egrep The Filename Analogy In DOS/Windows dir *.txt *、?:file globs or wildcards * :match anything ? :match any one character Generalized Pattern Language Regular Experssions: Powerful pattern language(generalized pattern language) and the patterns themselves The Language Analogy Regular Expressions are composed of: Metacharacters (special characters) Literal (normal text characters) Literal text acting as the words and metacharacters as the grammar. Part 2 Regular Expression Syntax Regular Expression測試小程式 .tw/blog/archives/ciyawasay/000381.html Regular Experssion的投影片與範例檔 .tw/blog/archives/ciyawasay/000394.html Start and End of the Line Start:^ (caret) End: $ (dollar) cat 、^cat 、cat$ Match a position in the line rather than any actual text characters themselves. Question:^cat$ 、^$ 、^各代表什麼意思? Character Classes Matching any one of several characters […] Negated character classes [^…] Matching any one of several characters […] grey、gray ? gr[ea]y [0-9]character-class metacharacter ‘-’ (dash) h[123456] ? h[1-6] [0-9a-fA-F] = [A-Fa-f0-9] A dash is a metacharacter only within a character class – otherwise it matches the normal dash character. Negated character classes [^…] Matches any character that isn’t listed. [^1-6] matches a character that’s not 1 through 6. Question:Why doesn’t q[^u] match ‘Qantas’ or ‘Iraq’ Character Class Notes A character class, even negated, still requires a character to match. Consider character classes as their own mini language. The rules regarding which metacharacters are supported (and what they do) are completely different inside and outside of character classes. Matching Any Character with Dot . (dot 、point) Matches any character 03

文档评论(0)

1亿VIP精品文档

相关文档