-1
4

1 回答 1

1

You need regex (well technically you don't need regex, but it's the best way):

if (aString.matches(".*(?<!\\\\)}.*"))

This regex says the string should be made up as follows

  • .* zero or more of any character
  • (?<!\\\\) the previous char is not a backslash
  • } a curly right bracket
  • .* zero or more of any character

This also works for the edge case of the first char being the curly bracket.

See live demo.

于 2019-02-26T22:17:44.223 回答