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
A negated character class should do the trick: str.matches(".*(?:^|[^.])xyz.*")
str.matches(".*(?:^|[^.])xyz.*")
Here we're using a non capturing group (?:^|[^.]) to ensure that we match either at the start of the string ^, or at any position that isn't a period [^.]
(?:^|[^.])
^
[^.]