python3 硬正则表达式

问题描述 投票:0回答:0

给出以下示例:

/bin/cat /home/user dir/file | /bin/grep "XXXXXX" && /bin/curl http://xxx.xxx.xxx.xxx/some/path -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST

使用 python3,如何在给定路径中获取一个随机字符 (不包括斜杠,例如:/bin/ - bin;/home/ - home;/user dir/ - user dir) 不包括 http 部分( 所以不是 http://xxx.xxx.xxx.xxx/some/path ),并替换那个字符 ( 但不是空白字符,所以在 /user dir/ 的情况下,那个空格在user 和 dir 应该被排除在替换 ) 之外,并打印完整字符串的新版本?

最终结果示例:

/bGn/cGt /Gome/user Gir/filG | /biG/grGp "XXXXXX" && /biG/curG http://xxx.xxx.xxx.xxx/some/path -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST

ps: /bin/cat 和 /bin/curl 只是一个例子,它可以是所有其他命令

python python-3.x regex random substitution
© www.soinside.com 2019 - 2024. All rights reserved.