Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.