How can I extract alphanumeric characters only from a string?
Example : b:lbalbqsd1287/;:!,
gives blbalbqsd1287
Is it possible with findstr
?
I think it can somehow be possible to do this in batch. I don't know how and I'm sure it's painful, not maintainable and ugly. But, as an alternative you can use a vbscript to do the job (also built-in and must be available in every OS).
I wrote this little guy here for your pleasure :)
Option Explicit
Dim sInput, sOutput
sInput = "b:lbalbqsd1287/;:!,"
sOutput = RegEXP_VBS(sInput)
Call MsgBox (sOutput)
Function RegEXP_VBS(sIn)
Dim oREGEXP, oResult, oMatch
Set oREGEXP = CreateObject("vbscript.regexp")
oREGEXP.IgnoreCase = False
oREGEXP.MultiLine = False
oREGEXP.Global = True
oREGEXP.Pattern = "[a-zA-Z0-9]"
Set oResult = oREGEXP.Execute(sIn)
For Each oMatch in oResult
RegEXP_VBS = RegEXP_VBS & oMatch.Value
Next
End Function
findstr
works on lines, not in lines and it never extract sth.