A lot depends on the fiber content of the affected carpet.
If it is wool, it's beyond help, imo
If it's polyester or olefin - lots of things should work - if all else fails try Chlorine bleach after testing.
If it's Nylon try a 1% solution of Chlorox - it usually comes @ 4% strength.
When you first go to assess one of these, pull a few of stained fibers as well as some unaffected fibers from nearby ( same light exposure and wear conditions ) and take them home.
Prepare a few different, small solutions of your favorite oxidizing and reducing agents and drop a fiber or two into each one to see which one(s) have any effect on the dye. When/if you find one, drop a few of the unstained fibers into that same solution to see if your solution will affect the undamaged fibers. Sometimes you may have to add back some color but often you can remove the dye/stain without having to do so.