提取剪切板尺寸数字.py 632 B

12345678910111213141516171819202122232425262728
  1. # python 读写剪切板内容, 先用下行命令安装运行库
  2. # python -m pip install pywin32
  3. import win32clipboard as w
  4. import win32con
  5. import re
  6. def getText():
  7. w.OpenClipboard()
  8. d = w.GetClipboardData(win32con.CF_TEXT)
  9. w.CloseClipboard()
  10. return(d).decode('GBK')
  11. def setText(aString):
  12. w.OpenClipboard()
  13. w.EmptyClipboard()
  14. w.SetClipboardText(aString)
  15. w.CloseClipboard()
  16. # 获取剪贴板文本
  17. text = getText()
  18. # print(text)
  19. # 正则搜索数字,写回剪贴板
  20. list = re.findall(r"[1-9][\d\.]*\d*[cmin\"]*", text)
  21. text = " ".join(list)
  22. print(text)
  23. setText(text)