Given:
public class Main { public static void main(String[] args) { for (int x = 1; x < args.length; x++) System.out.print(args[0].split(args[x]).length + " "); } }
And the command-line invocation:
java Main "x1 23 y #" "\d" "\s" "\w"
What is the result?
A is correct.
For the "regex-related" parts of the exam you need to remember the three metacharacters "\d" (which means digit), "\s" (which means a whitespace character), and "\w" (which means a word character-i.e., letters, digits, or the underscore character).
With that said, the calls to the split()
method are tokenizing
calls.
In this case, we're using metacharacters as our token delimiters.
In the first iteration of the for loop, digits are the delimiters.
In the second iteration, whitespace characters are the delimiters.
And in the final iteration, "word" characters are the delimiters.