Java Search Pattern Part 2

BIS
2 min readFeb 7, 2021

For our Online Test Software, Java Paper API is used heavily to mark the examination questions. For any Exam Software marking is a very important part and requires some way of automating the marking process.

Here is the process adopted for Examination Software

  1. Create a pattern string with a regular expression.
  2. Compile it so it can be used multiple times.
  3. apply matches(0 function.
  4. if matches() functions return true then a patter is a match
  5. if matches() return false then pattern does not exist inside the search text.
static void simpleMatchesTest(final String patternString, final String text) {
Pattern pattern = Pattern.compile(patternString);
Matcher matcher = pattern.matcher(text);
System.out.printf("%s found is : %s\n", patternString, matcher.matches());
}

Question Bank Software

Online Exam Software

Online Test System

Java Pattern API provides matcher pattern gives us more information about the matching. for Online Examination Software here is an excerpt of the code which gives detailed information about the match.

static void simpleMatcherTest(final String patternString, final String text) {

Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
int count = 0;
while (matcher.find()) {
count++;
System.out.printf("found: %d : %d - %d %n", count, matcher.start(), matcher.end());
}
}
Here is the output:

Here is the output: Online Assessment Software

Task :MatcherTest.main()
.*exam-system.* found is : true
.*test-system.* found is : false
found: 1 : 31 - 35
found: 2 : 50 - 54

Online Assessment System

Assessment Management Software

java pattern API allows you to group one or more patterns or searches together. which is used for Examination Management Software and Exam Management Software

static void simpleGroupTest(final String patternString, final String text) {

Pattern pattern = Pattern.compile(patternString, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.printf("found: %s %s %n", matcher.group(1), matcher.group(2));
}
}

Here is the complete illustration for the Group and Matcher: Online Examination System

public static void main(String[] args) {
String text = "https://www.onlinetestplus.com/exam-system/";
String patternString = ".*exam-system.*";
simpleMatchesTest(patternString, text);
patternString = ".*test-system.*";
simpleMatchesTest(patternString, text);

text = "https://www.onlinetestplus.com/exam-system/online-exam-software/";
patternString = "exam";
simpleMatcherTest(patternString, text);
patternString = "(exam)-(.+?/)";
simpleGroupTest(patternString, text);
}

Please visit the following links for detailed information and usages of the API pattern.

Examination Management System

Exam Management System

--

--