1

How can I extract alphanumeric characters only from a string?

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

Is it possible with findstr?

1
  • findstr works on lines, not in lines and it never extract sth.
    – Endoro
    May 3, 2013 at 19:47

1 Answer 1

0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .