Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Pattern Lab CS 240, In-class Regular-Expression Lab   Objectives: Gain familiarity parsing an input URL for email id's and URLs, using Java's regular expression pattern matching capabilities. Instructor email: kruse@juniata.edu Instructor webpage: http://jcsites.juniata.edu/faculty/kruse/ Tasks: Read up on Regular Expressions.  Think about regular expressions to match email ids and URLs. Read up on Java's Pattern class.  How would you declare and instantiate a Pattern Object (pay close attention to the compile method)?  What class is related to the Pattern class.  Pay particular attention to the Regular Expression constructs. Read up on Java's Matcher class.  In particular, consider how you would declare and instantiate a Matcher Object. Can you do it directly? Do you need to declare and instantiate some type of intermediate Object?  What parameter would you use for the constructor? Copy your Application class from the previous Lab to a new file (or, you may find this file helpful to start with: TDPatternInClass.java), and modify it as follows: Define a Pattern that matches a "word character" and followed by an @ sign and then followed by one or two "word characters.". You can use the Pattern class: Pattern emailPattern = Pattern.compile( fill-this-in-with-a-regular-expression ); Update the loop which is reading each token in the URL so that it checks each token for the emailPattern, and outputs the result if there is a match. You can use the Matcher class: Matcher emailMatch = emailPattern.matcher( fill-this-in-with-the-token-you-read-out-of-the-file ); and if ( emailMatch.find() ) { String patternFound = emailMatch.group(); } Compare the ouput of your application program to the source code of the URL you submit as input. Note that there are 9 emails embedded in comments in the html source for this web-page. Did you find them all? Are the ones you found complete/correct? Update your pattern to have it match more email ids. If you consult a search engine or other source for patterns to use, please be sure to cite your source. Finally, define a pattern to recognize URLs and output them as well.