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 by a period (.). So "xxyz" counts but "x.xyz" does not.
xyzThere("abcxyz") → true
xyzThere("abc.xyz") → false
xyzThere("xyz.abc") → true
I'm trying to solve this with a regex, but I'm unsure how to handle where the xyz is not directly preceeded by a period requirement.
My solution for the problem without the constraint is this:
public boolean xyzThere(String str) {
return str.matches(".*xyz.*");
}
Any idea how to handle the said constraint with a regex?