PDFファイルの仕様に従って名前オブジェクトを一致させる必要があります。ただし、特殊文字を指定するために、名前に 16 進数 (先頭に #) を含めることができます。これらの一致を対応する文字に変換したいと思います。一致文字列を再解析せずにそれを行う賢い方法はありますか?
import re
Name = re.compile(r'''
(/ # Literal "/"
(?: #
(?:\#[A-Fa-f0-9]{2}) # Hex numbers
| #
[^\x00-\x20 \x23 \x2f \x7e-\xff] # Other
)+ #
) #
''', re.VERBOSE)
# some examples
names = """
The following are examples of valid literal names:
Raw string Translation
1. /Adobe#20Green -> "Adobe Green"
2. /PANTONE#205757#20CV -> "PANTONE 5757 CV"
3. /paired#28#29parentheses -> "paired( )parentheses"
4. /The_Key_of_F#23_Minor -> "The_Key_of_F#_Minor"
5. /A#42 -> "AB"
6. /Name1
7. /ASomewhatLongerName
8. /A;Name_With-Various***Characters?
9. /1.2
10. /$$
11. /@pattern
12. /.notdef
"""