Yes that will work, though note that .
will not match newlines unless you pass the DOTALL flag when compiling the expression:
Pattern pattern = Pattern.compile(".*123", Pattern.DOTALL);Matcher matcher = pattern.matcher(inputStr);boolean matchFound = matcher.matches();