Answer the question
In order to leave comments, you need to log in
How to check if a character is in quotes in python?
Actually, let's say I have a string, it can consist of absolutely any characters, but, for example, punctuation marks must be in quotation marks. How can I do this check?
Answer the question
In order to leave comments, you need to log in
Here is the regular:
Fires if there is an even number of quotes (quotes are balanced) and there are punctuation marks between the odd (opening) and even (closing) quotes. In the example, punctuation marks are only a period and a comma (in the center of the regular expression), but you can add your own.
Demo: regexr.com/38oft
Here's a little simpler, catches punctuation marks outside of quotes:
^([^"]*("[^"]*")*[^"]*)*([,.])([^"]*("[^"]*")*[^"]*)*$
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question