Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
pattern = r'[ -\\[\\]]' regex = re.compile(pattern) name = '123[ shiv' new_name = regex.sub('_',name)
結果(new_name)を与える::
'_____shiv'
それ以外の::
'123__shiv'
..事前に感謝します
正規表現は、whitespace (ASCIIコード-32)からopening bracket - [(ASCIIコード-91 )までの範囲を作成しています。これは、その間にあるためです-。そして、その範囲には数字0 to 9 (ASCIIコード-48から57)が含まれます。
whitespace
opening bracket - [
-
0 to 9
正規表現を次のように変更する必要があります:-
pattern = '[- \\[\\]]'
最初に移動-しました。