Java Programming 3-2: Use regular expressions Practice Activities Lesson Objecti
ID: 3851979 • Letter: J
Question
Java Programming 3-2: Use regular expressions Practice Activities Lesson Objectives: Use regular expressions .Use regular expressions to search, parse, and replace strings. Vocabulary: Identify the vocabulary word for each definition below. Any symbol in regular expressions that indicates the number of occurrences a specified character appears in a matching string A regular expression symbol that represents any character will create a match A class in the java.util.regex package that stores the format of a regular expression Segments of regular expressions starting with "(" and ending with"", which may later be called by the Matcher method group(groupNumber) Used in regular expressions to allow character variability; may contain either a specified range of characters of a group of character options. A class in the java.util.regex package that stores the possible matches between a Pattern and a String. A character or sequence of characters that represents a string or multiple strings and allows for variability in matches.Explanation / Answer
Hi,
I could complete question 1 and 5 alone in the time allocated to answer. Please post the rest of the questions in another question-
Below are the answers-
Ans 1-a) To indicate the number of occurances of specified character in the string, we need to use the curly bracket.
Example - a) d{3} searches for three digits,
b) .{10} for any character sequence of length 10
Ans 1b) A regular expression symbol that represent a single character match is - "?"
Ans 1c) import java.util.regex
Ans 1d) Firstly, you can escape it using a backslash -- (
Alternatively, since it's a single character, you can put it in a character class, where it doesn't need to be escaped -- [(]
Ans 1e) Tp specify the range, we need to use the square brakets and then specify the range of characters inside it.
Example - To match any alphabet in the range A-Z or a to z
[a-zA-Z]
Ans 1f) import java.util.regex.Matcher
Ans 1g) To match a sequence of caracters of variable length, we need to use the "+" character which indicates one or more occurance of the regex pattern.
[a-zA-Z]+
Ans 5 -
part 1- since "?" character is used to match 0 or 1 occurance of the character in the string. Hence, the answer to the question will be-
str="anana";
and
str="banana"
part 2 -The [] bracket is used to match the set of character given in the bracket but only one character at a time.Hence, the answer will be-
str2="banana";
part 3 - As "*" matches zero or more occurance of character, the output will be-
str3="montanana";
str3="anana";
str3="_anana";
Regards,
Vinay Singh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.