What changes should be done to the string such that regular expression should match with ""abcd""?
You can make regex match ""abcd"" by adding another \"
from both sides to your code, and remove ()
(optional), no need for them. Your code will be:
\"\"[^\"]*\"\"
Demo: https://regex101.com/r/6sPoEc/6
If you want to limit what is inside the quotations to be only alphabetical, You can use [a-zA-Z].
\"\"[a-zA-Z]+\"\"
Demo: https://regex101.com/r/6sPoEc/5
If however you want to include alphabetics, numbers and underscore _
inside the quotation marks, use \w
\"\"[\w]+\"\"
Demo: https://regex101.com/r/6sPoEc/4
By the way, be careful with +
and *
.
+
can return at least one character or more while *
can return zero or more characters which means that *
can return empty quotations """"