I have a String array
String[] arrayOfLine = {
"I.2 Other Interpretive Provisions",
"I.3 Accounting Terms",
"Including all",
"II.1 The Loans",
"II.3 Prepayments.",
"III.2 Illegality",
"IV.2 Conditions",
"V.2 Authorization",
"expected to have"
};
I want to pick only those array elements which starts with roman.number i.e starting with I.2, II.1 and so on.
I am trying this, but it is not working
String regex = "\b[A-Z]+\\.[0-9]\b";
for (int i = 0; i < arrayOfLine.length; i++) {
if(arrayOfLine[i].matches(regex)){
listOfHeadings.add(arrayOfLine[i]);
}
}
\bmust be\\b. Also, you need to use.find()with aMatcherobject. It looks like you need to find all items that start with the pattern. If yes, use^[A-Z]+\\.[0-9].matcheswill attempt to match complete input. Use:"[A-Z]+\\.[0-9]\\b.*"arrayOfLine, can it contain values other than you mentioned ?