fork download
  1. import re
  2.  
  3. pattern = r'(\[tool\.poetry](?:\n(?!\[[^][]*]).*)*\nname = ")[^"\n]*(?=")'
  4.  
  5. s = ("[tool.poetry]\n"
  6. "version = \"0.1.0\"\n"
  7. "description = \"python is good\"\n"
  8. "name = \"template-python\"\n"
  9. "readme = \"README.md\"\n"
  10. "packages =[\n"
  11. " {include=\"projectname\"}\n"
  12. "]\n\n"
  13. "[tool.poetry.dependencies]\n"
  14. "python = \">=3.11,<3.13\"\n\n\n"
  15. "[tool.poetry.group.test.dependencies]\n"
  16. "pytest = \"^8.0.0\"\n\n\n"
  17. "[tool.pytest.ini_options]\n"
  18. "pythonpath = \".\"\n"
  19. "addopts = [\"-v\", \"-s\", \"--import-mode=importlib\"]\n"
  20. "name = \"hello\"")
  21.  
  22. result = re.sub(pattern, r"\1nameofproject", s)
  23. print(result)
Success #stdin #stdout 0.04s 9740KB
stdin
Standard input is empty
stdout
[tool.poetry]
version = "0.1.0"
description = "python is good"
name = "nameofproject"
readme = "README.md"
packages =[
    {include="projectname"}
]

[tool.poetry.dependencies]
python = ">=3.11,<3.13"


[tool.poetry.group.test.dependencies]
pytest = "^8.0.0"


[tool.pytest.ini_options]
pythonpath = "."
addopts = ["-v", "-s", "--import-mode=importlib"]
name = "hello"