【问题标题】:Find a substring next to a substring from a given string从给定字符串的子字符串旁边查找子字符串
【发布时间】:2023-01-19 12:31:57
【问题描述】:

如何从给定字符串中找到提到的子字符串旁边的子字符串。

例如:

string = "无法增加索引orcl_index的空间。索引orcl_index的空间应该增加250mb"

这里的指标子字符串是“index”,所需的输出将是“orcl_index”。

我尝试了以下代码,但不确定如何继续

my_string = "unable to increase the space of the index orcl_index. The space for the index orcl_index should be increased by 250mb"

print(my_string.split("tablespace",1)[1])

a= my_string.split("tablespace",1)[1]

b= a.strip()
print(b)

Output:" orcl_index should be increased by 250mb"

Required output: "orcl_index"

【问题讨论】:

    标签: python robotframework


    【解决方案1】:

    如果您愿意使用正则表达式,则有一种直接的方法:

    import re
    
    inp = "unable to increase the space of the index orcl_index. The space for the index orcl_index should be increased by 250mb"
    val = re.search(r'index (w+)', inp).group(1)
    print(val)  # orcl_index
    

    【讨论】:

      猜你喜欢
      • 2012-09-07
      • 1970-01-01
      • 2016-04-13
      • 2013-10-22
      • 1970-01-01
      • 1970-01-01
      • 2011-07-13
      相关资源
      最近更新 更多