python 截取指定字符串前尾

例如:
%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
并分开保存他们,操作方法如下:

1	>>> 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'
2	>>> b = 'roup_concat%28table_name%29'
3	>>> before = s[:s.index(b)-1]
4	>>> after = s[s.index(b)+len(b):]
5	>>> before
6	'%20and%201=2%20union%20select%201,'
7	>>> after
8	',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'
9	>>>

灵活运用的话,可以截取你想要的任意字符段。