Removing non alphanumeric characters in a batch variable
In batch, how would I remove all non alphanumeric (a-z,A-Z,0-9,_) characters from a variable? I'm pretty sure I need to use findstr and a regex. The solutionof MC ND works, but it's really slow (Needs ~1second for the small test sample). This is caused by the echo "!_buf!"|findstr ... construct, as for each character the pipe creates two instances of cmd.exe and starts findstr . But this can be solved also with pure batch. Each character is tested if it is in the map variable :test set "_input=Th""i\s&& is not good _maybe_???" set "_output=" set "map=abcdefghijklmnopqrstuvwxyz 1234567890"