Open callumgare opened 7 months ago
Refering to python regex documentation:
$ Matches the end of the string or just before the newline at the end of the string (...)
schema
Regex
class is build python re
. It looks like a feature.
note that you may have written too many \
.
under windows:
>>> Regex("^a$").validate("a")
'a'
>>> Regex("^a$").validate("a\n")
'a\n'
>>> Regex("^a$").validate(r"a\n")
schema.SchemaError: Regex('^a$') does not match 'a\\n'
>>> Regex("^a$").validate("a\\n")
schema.SchemaError: Regex('^a$') does not match 'a\\n'
The string
a\n
should fail validation with the schemaRegex("^a$")
but that does not happen. You can see this by running:This appears to only be true for a single trailing newline. Multiple trailing newlines or a leading newline both fail as expected:
I had a look though the existing issues but can't see this reported anywhere. I'm using the latest version (0.7.5) with Python 3.11.6 on macOS.
Thanks!