Reputation: 1854
The regex that I have to write is to match a single or double quoted strings (string that begin with single or double quoted string and end with the same type) and inside the quote do not contain any other instances of that type of quote.
What I have so far is
^('|").*\1
but I do not know how to control that inside the quote does not contain the same type of quote.
Upvotes: 0
Views: 150
Reputation: 234857
How about
Pattern p = Pattern.compile("^(\"[^\"]*\"|'[^']*')$");
Not as elegant as using \1
, but it should get the job done.
Upvotes: 3