So I'm doing a little bit of testing for something and I require a method of splitting a string into groups of two. (e.g. 'abcdef' => ['ab','cd','ef']
)
I'm trying to use a regex pattern to do this ([^]{2}
). Whenever I try to compile this pattern, I get the error message:
sre_constants.error: unexpected end of regular expression
The exact line of code is:
pat = re.compile(r'[^]{2}')
Could someone please tell me what I'm doing wrong here? I've done a lot of searching but a lot of the problems were related to incorrect usage and/or backslashes.
I thought about it possibly being because of string formatting, though the Python docs didn't mention anything about any issues.