Optimized fragment extraction with regular expressions