-1

I need to escape a left curly brace but not a right curly brace in my java regex.

My question is what's special about the left curly brace? Is it similar to say a normal bracket ( where the bracket is used for another purpose in regex (ie a group)? If so please share an example of the use case.

Why do I only need to escape left but not right curly brace?

alwayscurious
  • 925
  • 1
  • 5
  • 14

1 Answers1

1

The syntax of repetition is {min,max}. a{1,3} matches a, aa or aaa. If you don't escape the { it will be interpreted as a start of a repetition group that should be matched with a closing }.

Marc Lambrichs
  • 2,784
  • 2
  • 10
  • 14