Reputation: 5352
I am trying to define this regex to detect the tag in my xml file
I have written the following code:
val regex = """<!DOCTYPE[^>[]*(\[[^]]*\])?>""".r
but it gives me the following error
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 27
<!DOCTYPE[^>[]*(\[[^]]*\])?>
^
What am I doing wrong?
Upvotes: 0
Views: 411
Reputation: 95968
<!DOCTYPE[^>[]*(\[[^]]*\])?>
↑ ↑
You should escape the ]
and [
inside the sets:
<!DOCTYPE[^>\[]*(\[[^\]]*\])?>
Upvotes: 1
Reputation: 174716
Escape the ]
, [
present inside the character class.
val regex = """<!DOCTYPE[^>\[]*(\[[^\]]*\])?>""".r
Upvotes: 1