regex - Extract various characters from string (Alternate method) -
ok, have garbled text strings , want extract lower-case characters, upper-case characters , numerical values string 3 sub-strings , later use them purpose. have code this:
sinput = "awsedrgy vgiycfry2345ewscfvg gyifvygxscyui^rsfv gyd&k^dfyuodvl234sdv8p7ogyhs" local slower, supper, snumbers = "", "", "" sinput:gsub("%l", function(s) slower=slower..s end) sinput:gsub("%u", function(s) supper=supper..s end) sinput:gsub("%d", function(s) snumbers=snumbers..tostring(s) end) print( slower, supper, snumbers )
and working fine. not sure on using these 3 separate extractions 30,000 lines of such garbled text. there more efficient way? or way best possible solution?
try using complement classes:
sinput = "awsedrgy vgiycfry2345ewscfvg gyifvygxscyui^rsfv gyd&k^dfyuodvl234sdv8p7ogyhs" local slower = sinput:gsub("%l","") local supper = sinput:gsub("%u","") local snumbers = sinput:gsub("%d","") print( slower, supper, snumbers )
Comments
Post a Comment