Professional Documents
Culture Documents
SWD02 Regular Expressions in Java in Class Exercise
SWD02 Regular Expressions in Java in Class Exercise
16.2.2022
Haaga-Helia University of Applied Sciences
Programming 1
Answers
A. Write all the strings that match the Java regular expression patterns below;
1) String “1” String “2”
2) String “11”
3) String ”11” String “111”
4) String “121212”
5) String “121212”
6) String “cart”
7) String “cab” String “car” String “cat”
8) String “cab” String “cart”
9) String “Yum” String ”YumYum”
10) Strings “” “yum” “Yum” “yummy” “Yummy”
11) Strings “ban” “can” “dan” “ean” “fan” “man” “van”
12) Strings with digits between “-0” to “-59”
13) Cello
14) \\
matches only with character combo => String; 1any single character be
sides linebreak5
C. Does the Java regular expression pattern below match any of the given strings when we use
the match method of the String class?
“Hello,{0,2}Joe!” “Joe” No
“Joe!” No
“Hello, Joe!” No
“Hello Joe!” No
“Hello,Joe!” Yes
“Hello,Hello,Joe!” No
D. Does the Java regular expression pattern below match any of the given strings when we
use the match method of the String class?
“.{0,}Joe.{0,}” “Joe”
“Hello, Joe!”
Lasse Myllärinen Exercise 2 (2)
16.2.2022
Haaga-Helia University of Applied Sciences
Programming 1
“Hello, Joeseph!”
“.{0,}\\.class” “RegExExample.class”
“.class”
2{1,}2=4
2{0,}2=4