「Python」符号^で文字を否定で指定するサンプル

構文
[^Y] Y以外の文字を指定
サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
import re
x = "[^Y]"
res = re.findall(x,'KFC')
if res:
print(res[0])
print(res[1])
else:
print(res)
# coding: utf-8 import re x = "[^Y]" res = re.findall(x,'KFC') if res: print(res[0]) print(res[1]) else: print(res)
# coding: utf-8
import re

x = "[^Y]"

res = re.findall(x,'KFC')
if res:
      print(res[0])
      print(res[1]) 
else:
      print(res)

結果
K
F

Python

Posted by arkgame