Simplified regex algorithm implementation