Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I extract alphanumeric characters only from a string?

Example : b:lbalbqsd1287/;:!, gives blbalbqsd1287

Is it possible with findstr?

share|improve this question
findstr works on lines, not in lines and it never extract sth. – Endoro May 3 '13 at 19:47
up vote 0 down vote accepted

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

As you can see it uses regular expression for the job which you can change fairly easy if the scope of search-string changes.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.