invasion
invasion

Reputation: 111

Regex sentence shouldn't start or end with "

How does the regular expression work, so that no " characters are allowed at the beginning and the end of a sentence. Examples:

Test "if" that works --> is allowed
"Test" if that works --> is not allowed
Test if that "works" --> is also not allowed

So the quotes are only allowed in the middle of the sentence.

Upvotes: 0

Views: 131

Answers (2)

zipa
zipa

Reputation: 27879

This should do it:

^(?!").*(?<!")$

Regex101

Upvotes: 2

Nordle
Nordle

Reputation: 2981

You'll need to check depending on which language you're using, but you can use the regex '^\"|\"$' to capture a string with a quotation mark (") at the beginning or end of the string.

Upvotes: 1

Related Questions