I have an section id A00-A09
. Anything like A01
, A01.01
, A02
till A09.09
should be
classified under this section id. How can i do this in Python? At the moment I can only match string with exact character.
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
You can use
[]
with re module:output:
Non occurance:
output:
Use
re.match()
to check this. here is an example:Here the regex means
A0X
is mandatory, and.0X
is optional.X
is from0-9
.Cut the section id and compare:
You can do partial matches using
startswith()
andendswith()
. Assuming the full id is always in aX12.Y34
- each part is a letter and two numbers, separated by.
or-
(or any character):And you can convert it to uppercase if the input can sometimes be lowercase.