我有一個像蟒蛇:去掉最左邊的實例匹配的正則表達式
xp = /dir/dir/dir[2]/dir/dir[5]/dir
字符串我想
xp = /dir/dir/dir[2]/dir/dir/dir
xp.replace(r'\[([^]]*)\]', '')
刪除所有方括號,我只是想刪除就遠遠的一個剩下。
也應該完全忽略方括號not(random_number_of_characters)
前/dir/dir/dir[2]/dir/dir[5]/dir[1][not(random_number_of_characters)]
應該產生/dir/dir/dir[2]/dir/dir[5]/dir[not(random_number_of_characters)]
前。 /dir/dir/dir[2]/dir/dir[5]/dir[not(random_number_of_characters)]
應產生/dir/dir/dir[2]/dir/dir/dir[not(random_number_of_characters)]
你要刪除的最後'[]'括號? – 2014-08-27 10:19:11
括號內是否有一個或多個數字需要刪除,即。 ''/ dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir/dir// dir [2]/dir/dir [A]/dir''不變? – mhawke 2014-08-27 12:02:38