欢迎来到天天文库
浏览记录
ID:25130804
大小:2.04 MB
页数:50页
时间:2018-11-17
《regular expression与java》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、RegularExpression與Java蕭宇程swanky.hsiao@gmail.comhttp://swanky.adsldns.org/IntroductiontoRegularExpressionsRegularExpressionSyntaxObjectModelsUsingregexesinJavaPart1:IntroductiontoRegularExpressionsRegularexpressionsarethekeytopowerful,flexible,andefficienttext
2、processing.SearchingTextFiles:egrepTheFilenameAnalogyInDOS/Windowsdir*.txt*、?:fileglobsorwildcards*:matchanything?:matchanyonecharacterGeneralizedPatternLanguageRegularExperssions:Powerfulpatternlanguage(generalizedpatternlanguage)andthepatternsthemselvesTheL
3、anguageAnalogyRegularExpressionsarecomposedof:Metacharacters(specialcharacters)Literal(normaltextcharacters)Literaltextactingasthewordsandmetacharactersasthegrammar.Part2RegularExpressionSyntaxRegularExpression測試小程式http://www.javaworld.com.tw/blog/archives/c
4、iyawasay/000381.htmlRegularExperssion的投影片與範例檔http://www.javaworld.com.tw/blog/archives/ciyawasay/000394.htmlStartandEndoftheLineStart:^(caret)End:$(dollar)cat、^cat、cat$Matchapositioninthelineratherthananyactualtextcharactersthemselves.Question:^cat$、^$、^各代表什麼
5、意思?CharacterClassesMatchinganyoneofseveralcharacters[…]Negatedcharacterclasses[^…]Matchinganyoneofseveralcharacters[…]grey、gray⇒gr[ea]y[0-9]character-classmetacharacter‘-’(dash)⇒[0-9a-fA-F]=[A-Fa-f0-9]Adashisametacharacteronlywithinacharact
6、erclass–otherwiseitmatchesthenormaldashcharacter.Negatedcharacterclasses[^…]Matchesanycharacterthatisn’tlisted.[^1-6]matchesacharacterthat’snot1through6.Question:Whydoesn’tq[^u]match‘Qantas’or‘Iraq’CharacterClassNotesAcharacterclass,evennegated,stillrequiresa
7、charactertomatch.Considercharacterclassesastheirownminilanguage.Therulesregardingwhichmetacharactersaresupported(andwhattheydo)arecompletelydifferentinsideandoutsideofcharacterclasses.MatchingAnyCharacterwithDot.(dot、point)Matchesanycharacter03.19.76⇒03a19●76
8、03/19/76、03-19-76、03.19.76⇒03[-./]19[-./]76Thedotsarenotmetacharacterswithinacharacterclass[.-/]wouldbeamistakeAlternationMatchinganyoneofseveralsubexperssions
9、(or、bar)Combinemultipleexpe
此文档下载收益归作者所有