【python】截取指定字符串前尾

bbsyuewu 发布于 2012/08/03 18:40
阅读 6K+
收藏 0

例如:
%20and%201=2%20union%20select%201,group_concat%28table_name%29,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29

如何我想要截取指定字符串group_concat%28table_name%29前后的字符串,

%20and%201=2%20union%20select%201,  和  ,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29
并分开保存他们, 该如何处理?

说明: 因为前尾字符串是动态的, 所以选择指定字符串截取。

加载中
0
出云之月
出云之月

您这是唱哪出?

具体点例子吗?

0
bbsyuewu
bbsyuewu

额   简单点的例子:  啊哈

截取dododododonotfuckmeordoododosuckme

截取fuckme前后的字符串,并分开保存  THX!

0
骠骑将军
骠骑将军
>>> s = '%20and%201=2%20union%20select%201,group_concat%28table_name%29,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> b = 'roup_concat%28table_name%29'
>>> before = s[:s.index(b)-1]
>>> after = s[s.index(b)+len(b):]
>>> before
'%20and%201=2%20union%20select%201,'
>>> after
',3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> 

0
bbsyuewu
bbsyuewu

引用来自“骠骑将军”的答案

>>> s = '%20and%201=2%20union%20select%201,group_concat%28table_name%29,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> b = 'roup_concat%28table_name%29'
>>> before = s[:s.index(b)-1]
>>> after = s[s.index(b)+len(b):]
>>> before
'%20and%201=2%20union%20select%201,'
>>> after
',3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> 

灰常感谢兄弟的帮助, 在此谢过!
neverno
neverno
够简洁,赞~
mahone
mahone
就这样?我擦。。。
0
___py_liang
___py_liang

引用来自“骠骑将军”的答案

>>> s = '%20and%201=2%20union%20select%201,group_concat%28table_name%29,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> b = 'roup_concat%28table_name%29'
>>> before = s[:s.index(b)-1]
>>> after = s[s.index(b)+len(b):]
>>> before
'%20and%201=2%20union%20select%201,'
>>> after
',3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20%20from%20information_schema.tables%20where%20table_schema=database%28%29'
>>> 

边界不对呢

>>> before = s[:s.index(b)-1]
改成:
>>> before = s[:s.index(b)]
0
p
pyman

我也来。

 

>>> a="dododododonotfuckmeordoododosuckme"
>>> a.split("fuckme")
['dododododonot', 'ordoododosuckme']
>>> 

0
p
pyman
直接返回一个列表回来不就好了。
返回顶部
顶部