반응형

 

좌우 공백 문자와 제어 코드 문자 제거

 

import re

 

user_id = " \x08h_team \t\n" # 예 (:0x08(BackSpace), \t:Tab, \n:NewLine)

cleaned_id = re.sub(r'[\x00-\x1F\x7F]', '', user_id).strip() # 비가시 문자 제거 후 공백 제거

 

print('원문: "' + user_id + '"')

print('결과: "' + cleaned_id + '"')

 

 

[실행 결과]

 

원문: " h_team

"

결과: "h_team"

 

 

반응형

+ Recent posts