이름 개체과 일치해야합니다 (pdf 파일 사양 참조). 그러나 이름에는 특수자를 지정하는 16 진수 (#가 앞에 붙음)가 포함될 수 있습니다. 이 경기를 해당 문자로 번역하고 싶습니다. 일치 문자열을 다시 구문 분석하지 않고도이를 수행 할 수있는 영리한 방법이 있습니까?regex match groups 번역하기
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
"""
입력 문자열에서 이것을 바꾸시겠습니까? 아니면 일치하는 이름을 이스케이프 처리되지 않은 이스케이프 시퀀스와 함께 나열 하시겠습니까? –
're.sub '를 사용할 수 있습니까? –
@MartijnPieters - 이스케이프 시퀀스와 이스케이프 시퀀스가 일치하지 않는 목록을 나열하십시오. – root