Hi,
I need to validate with regular expression the maximum number of characters per line and the a maximum number of lines. I've managed to use a regex for max number of characters per line.
int maxRows = 3;
String strPattern = "^.{0,100}$";// 100 characters per line
Pattern pattern = Pattern.compile(strPattern, Pattern.MULTILINE);
Matcher matcher = pattern.matcher(value);
boolean found = false;
int index = 0;
while (matcher.find()) {
System.out.println(String.format("I found the text \"%s\" starting at "
+ "index %d and ending at index %d.%n", matcher.group(), matcher.start(),matcher.end()));
found = true;
index ++;
}
return found && (index <= maxRows);
I'm interested to remove the while loop from code and change the pattern used to match maxRows.
Thanks,
Catalin