HowieJ Posted June 15, 2010 Share Posted June 15, 2010 Lets say I have a string = "eraTESf ER , - 347 DFE,ad" I want to format to be only letters(lower and upper), take away everything else including the space So in result, it should be "eraTESfERDFEad" How can I achieve this using StringRegExp ? or perhaps some better option ? Thank you for any help Howie Link to comment Share on other sites More sharing options...
Bert Posted June 15, 2010 Share Posted June 15, 2010 Try this to figure it out: http://rubular.com/ I find it helps in figuring it out quickly. The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
jchd Posted June 15, 2010 Share Posted June 15, 2010 Assuming you mean ASCII letters (i.e. english letters) only, try this: $string = "eraTESf ER , - 347 DFE,ad" $result = StringRegExpReplace($string, "(?i)[^a-z]", "") This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
HowieJ Posted June 15, 2010 Author Share Posted June 15, 2010 Thank you Volly. This is very helpful. I had below code. $string = "eraTESf ER , - 347 DFE,ad" $formatted = StringRegExp($string, "[a-zA-Z]") msg(0,"",$formatted) How come $formatted always result 1 ? Thanks Link to comment Share on other sites More sharing options...
jchd Posted June 15, 2010 Share Posted June 15, 2010 The regexp option you use (third parameter defaults to 0) return a bolean result 0 or 1 meaning no match or match. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
HowieJ Posted June 15, 2010 Author Share Posted June 15, 2010 Hi, Thanks for the help. I guess I was in the wrong direction. I had below code which will format string from "ajvelrjlejrje*&^%$#@!_)(+_-=':'/.,><}{][\|akr2342343" --> "ajvelrjlejrje" $test = "ajvelrjlejrje*&^%$#@!_)(+_-=':'/.,><}{][\|akr2342343" $testarray = StringSplit($test,"") ;MsgBox(0,"",$testarray[0]) $formatted ="" for $i = 1 to $testarray[0] if StringIsAlpha($testarray[$i]) Then $formatted = $formatted & $testarray[$i] EndIf Next MsgBox(0,"",$formatted) I am just wondering if there is any better way to achieve this. Thank Link to comment Share on other sites More sharing options...
jchd Posted June 15, 2010 Share Posted June 15, 2010 That's indeed overcomplex! Look again 4 posts above. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
UEZ Posted June 15, 2010 Share Posted June 15, 2010 (edited) This is working for me: $test = "ajvelrjlejrje*&^%$z#Z@!_)ABC(+_-=':'/.,><}{][\|akr2342343" $StrReg = StringRegExpReplace($test, "[\W\d^\_]", "") $testarray = StringSplit($test,"") ;MsgBox(0,"",$testarray[0]) $formatted ="" for $i = 1 to $testarray[0] if StringIsAlpha($testarray[$i]) Then $formatted = $formatted & $testarray[$i] EndIf Next MsgBox(0,"",$formatted & @CRLF & $StrReg) BR, UEZ Edited June 15, 2010 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
HowieJ Posted June 15, 2010 Author Share Posted June 15, 2010 Assuming you mean ASCII letters (i.e. english letters) only, try this: $string = "eraTESf ER , - 347 DFE,ad" $result = StringRegExpReplace($string, "(?i)[^a-z]", "") Thank you for your help. This is what I am looking . Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now