Java Programming Ideas-13th chapter-some exercises

Source: Internet
Author: User
Tags true true

. Match any one character

* Indicates a match of 0 or more preceding this character

+ represents 1 or more of the preceding characters

? Represents 0 or 1 of the preceding character

^ Indicates the start of a line ^[a-za-z]: Indicates a A-Z or a-Z start

[^0-9]: Denotes not a number, except a number

$ indicates the end of a line

Question seventh:

  Package net.mindview.strings.test7;
PublicClassTEST7 {PublicStaticvoidMain (string[] args) {//Both formulations can be String regex ="^[a-z].*\\.$";//"^[a-z].*\\." It's also trueString regex1 ="\\p{upper}.*\\.$"; String str ="D."; String str1 ="Dfasdfasfasfdasfdasfasfasdf."; String str2 = "dfasdfasfasfdasfdasfasfasdf.e"; System. out. println (Str.matches (regex)); System. out. println (Str1.matches (regex)); System. out. println (Str2.matches (regex)); System. out. println (Str.matches (REGEX1)); System. out. println (Str1.matches (REGEX1)); System. out. println (Str2.matches (REGEX1));}}             

Operation Result:

  true
Truefalse    true True False

Question Eighth

Package Net.mindview.strings;import java.util.Arrays;PublicClassSplitting {Publicstatic String Knights ="Then if you had found the shrubbery, you must cut off the mightiest tree in the forest ... a herring!";PublicStaticvoidSplit (String regex) {System.Out. println (Arrays.tostring (Knights.split (regex))); }PublicStaticvoidMain (string[] args) {//Splits a string by a space when represented//Running results: [Then, when, you, has, found, the, shrubbery,, you, must, cut, down, the, mightiest, tree, in, the, forest ..., with ..., a, herring!] Split""// means to split the string by non-single character--where the non-single character is a space and   running result: [then] when, you, has, found, the, shrubbery, you, must, cut, down, the, mightiest, T Ree, in, the, forest, with, a, herring] split ( "\\w+ "); // This means: split the string with N before the one-time character here the delimiter is n spaces and N, // run result: [The, whe, you had found the shrubbery, you must cut Dow, the Mightie St Tree I, the forest ... with ... a herring!] Split ( "n\\w+"  
Package Net.mindview.strings.test8;import net.mindview.strings.Splitting;  class Test8 {        void"the|you"; Splitting.split (regex); }}

Question Nineth

Package Net.mindview.strings.test9;import net.mindview.strings.Splitting;PublicClassTest9 {PublicStaticvoidMain (string[] args) {String regex ="a| e| i| o| U|a|e|i|o|u";//A case-insensitive match can also be enabled through an inline flag expression (? i). String regex1 ="(? i) a|e|i|o|u";//[ABC "denotes a or B or c String regex2 =  " (? i) [Aeiou]" ; System. out.println (Splitting.knights.replaceAll (regex,  " Span style= "COLOR: #800000" >_ "out.println (Splitting.knights.replaceAll (regex1,  " Span style= "COLOR: #800000" >_ "out.println (Splitting.knights.replaceAll (regex2,  " Span style= "COLOR: #800000" >_ "    

Java Programming Ideas-13th chapter-some exercises

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.