I\'m trying to solve this CodingBat problem:
Return true if the given string contains an appearance of \"xyz\" where the xyz is not directly preceeded
I personally used this solution, but there are quite a number of other variants:
str.matches("(.*[^.])?xyz.*")
I just make sure that if there is anything in front of xyz, then the period . does not immediately precede.
You can also write a look-behind solution:
str.matches(".*(?
(? part is negative lookbehind, and \\. (literal period) is the pattern that we want to check against.