Seems this approach has a slight edge over using regex.
I had a look at some of the unittests but could find a good fit for this, but admittedly I haven't used pytest before. If someone wanted to point me in the right direction to get started I could add some.