I'm doing a project which requires numerical pattern matching.
For example i want to know whether Value = 1331 is a part of 680+651 = 1331 or not, i.e. i want to match 1331 with 680+651 = 1331 or any other given string.
I'm trying pattern matching in java for the first time and i could not succeed. Below is my code snippet.
String REGEX1=s1; //s1 is '1331'
pattern = Pattern.compile(REGEX1);
matcher = pattern.matcher(line_out); //line_out is for ex. 680+651 = 1331
System.out.println("lookingAt(): "+matcher.lookingAt());
System.out.println("matches(): "+matcher.matches());
It is returning false all the times. Pls help me.
matches() requires that the pattern be a complete match, not a partial.
You either need to change your pattern to something like .*= 1331$ or use the find() method which will do a partial match.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With