Mat.S
Mat.S

Reputation: 1854

Not Contain REGEX

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

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234857

How about

Pattern p = Pattern.compile("^(\"[^\"]*\"|'[^']*')$");

Not as elegant as using \1, but it should get the job done.

Upvotes: 3

Related Questions