{ ; all fine here: TString s2 = "premoderator-2um-10mm-5-5cm-200gauss-0deg-G4_W-lhexa-100000.txt"; TString p2 = "premoderator-(.*)um-(.*)mm-(.*)-(.*)cm-(.*)gauss-(.*)deg-(.*)-(.*)-(.*)\.txt"; TString r2 = "$1; $2; $3; $4; $5; $6; $7; $8; $9"; TPRegexp(p2).Substitute(s2, r2); cout << s2 << endl; ; but with problems in this place: TString s1 = "premoderator-2um-10mm-5-5cm-200gauss-0deg-G4_W-lhexa-100000-long-none.txt"; TString p1 = "premoderator-(.*)um-(.*)mm-(.*)-(.*)cm-(.*)gauss-(.*)deg-(.*)-(.*)-(.*)-(.*)-(.*)\.txt"; TString r1 = "$1; $2; $3; $4; $5; $6; $7; $8; $9; $10; $11"; TPRegexp(p1).Substitute(s1, r1); cout << s1 << endl; }