diff --git a/Lib/csv.py b/Lib/csv.py index dc85077f3ec663..93f9fc7260c6d8 100644 --- a/Lib/csv.py +++ b/Lib/csv.py @@ -214,10 +214,10 @@ def _guess_quote_and_delimiter(self, data, delimiters): """ matches = [] - for restr in (r'(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?P=delim)', # ,".*?", - r'(?:^|\n)(?P["\']).*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", - r'(?P[^\w\n"\'])(?P ?)(?P["\']).*?(?P=quote)(?:$|\n)', # ,".*?" - r'(?:^|\n)(?P["\']).*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) + for restr in (r'(?P[^\w\n"\'])(?P ?)(?P["\'])[^\n]*?(?P=quote)(?P=delim)', # ,".*?", + r'(?:^|\n)(?P["\'])[^\n]*?(?P=quote)(?P[^\w\n"\'])(?P ?)', # ".*?", + r'(?P[^\w\n"\'])(?P ?)(?P["\'])[^\n]*?(?P=quote)(?:$|\n)', # ,".*?" + r'(?:^|\n)(?P["\'])[^\n]*?(?P=quote)(?:$|\n)'): # ".*?" (no delim, no space) regexp = re.compile(restr, re.DOTALL | re.MULTILINE) matches = regexp.findall(data) if matches: