【问题标题】:find a set of path within a string using regex in python [closed]在python中使用正则表达式在字符串中查找一组路径[关闭]
【发布时间】:2015-02-06 21:26:41
【问题描述】:

我有一个字符串,随着时间的推移可能会变大。我需要找出字符串中的工件路径。有没有办法让所有工件路径都使用正则表达式突出显示?我已经引用了它们。在这种情况下,雷鬼会是什么?

/usr/lib64/python2.6/site-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
  _warn("Not using mpz_powm_sec.  You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
[SSH] exit-status: 0
For pattern: *.py 10 artifacts were found
For pattern: *.md 1 artifacts were found
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/elb_ec2Connector.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/elb_ec2Connector_Tony.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_weekend_stop.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_4th_box.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/startontags.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/nitish.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/krishna.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_weekend.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/get-pip.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/startup_script.py
Deploying artifact: artifactory/artifactory/yum-local/test/test2/test3/test4/test5/test6/README.m

Deploying build info to: artifactory/artifactory/api/build
Collecting metadata...
Metadata collection done.

上面的全部是字符串,我需要想办法从中获取以下部分:

Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/elb_ec2Connector.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/elb_ec2Connector_Tony.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_weekend_stop.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_4th_box.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/startontags.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/nitish.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/krishna.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/naren_weekend.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/get-pip.py
Deploying artifact: artifactory/artifactory/yum-local/test/test4/test5/startup_script.py
Deploying artifact: artifactory/artifactory/yum-local/test/test2/test3/test4/test5/test6/README.m

请记住,路径可能会不断更改其他字符串,尽管初始单词部署工件将保持不变,并且所有路径将一起出现在日志中...

【问题讨论】:

  • 字符串是什么?整件事?你想走的路是什么?我们需要具体的示例输入和输出
  • @AdamSmith - 现在检查。

标签: python regex python-2.7


【解决方案1】:

看起来很简单。

artifact_paths = re.findall(r"^Deploying artifact: .*$", full_string, re.M)

【讨论】:

  • 抱歉,第一次使用正则表达式。我试过这个它返回空列表......
  • @Scooby 哎呀,我的错,忘记了多行字符串,您必须使用 re.M 来获得 ^ $ 行为。已编辑。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-28
  • 1970-01-01
相关资源
最近更新 更多