MyEarth Posted July 4, 2013 Share Posted July 4, 2013 I want to check if a string has special char ( all the special char like .+*@ etc., i want only numbers and letters and nothing else ) so i have try with StringInString but seems not work $string = "fdaafsdfsafa@" $a = StringInStr($string, '!"£$%/\(|)=?^ìè+òàù,.-é*ç°§;:_@#') ConsoleWrite($a) I don't want to replace it, but give an error if found a special char in the string Thanks Link to comment Share on other sites More sharing options...
M4n0x Posted July 4, 2013 Share Posted July 4, 2013 (edited) Hi, Try with StringRegEx like this : $sStr = "test@" $result = StringRegExp($sStr, "[@éèà]") MsgBox(0, "Result", $result) take a look here : http://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm Edited July 4, 2013 by M4n0x Link to comment Share on other sites More sharing options...
jchd Posted July 4, 2013 Share Posted July 4, 2013 It might be even easier to specify what character range are allowable in the regexp. 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...
MyEarth Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) Pratically in StringRegEx i need to use the: [\W] For matching any special char? I'd like to have only letters and numbers in my string, or maybe i can do the opposite and search for digit and letters? Edited July 4, 2013 by MyEarth Link to comment Share on other sites More sharing options...
M4n0x Posted July 4, 2013 Share Posted July 4, 2013 (edited) @jchd, Un français ! La communauté francophone est bien présente, ça fait plaisir perhaps, somethings like this : $sStr = "fdaafsdfsaf@a" $iResult = StringRegExp($sStr, "^(?-i)[a-z\s0-9]*$") if $iResult Then Msgbox(0,"","Value OK") Else Msgbox(0,"","Value KO") EndIf Edited July 4, 2013 by M4n0x Link to comment Share on other sites More sharing options...
orbs Posted July 4, 2013 Share Posted July 4, 2013 "i want only numbers and letters and nothing else" - StringIsAlNum() should do it. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
Malkey Posted July 4, 2013 Share Posted July 4, 2013 Apparently, the regexp matching character "W" and the 'StringIsAlNum' function both allow the underscore character "_" in their list of alphanumeric characters. @ M4n0x "(?-i)" is the default and therefore an unnecessary case-sensitivity flag. So your example is calling the capital A to Z letters unwanted special characters. You probably meant to use "(?i)" for case-insensitivity. This example below is labelling all non-letters (upper and lower case) and non-numbers as unwanted special characters. Other unwanted special characters include the underscore, horizontal and vertical whitespace characters, and a decimal point or fullstop. Local $string = "fBa0a1fAsd_fs2a" If StringRegExp($string, '[^a-zA-Z0-9]') Then MsgBox(0, "Results", "String has a special character", 3) Else MsgBox(0, "Results", "String does not have any special characters present.", 3) EndIf Link to comment Share on other sites More sharing options...
jchd Posted July 4, 2013 Share Posted July 4, 2013 M4n0X, There are even more French users on the French forum! 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...
M4n0x Posted July 4, 2013 Share Posted July 4, 2013 @Malkey, apologize ! i would meant "(?i)" for insensitive case as you say. so, corrected here, thanks $sStr = "fdaafsdfk#safa" $iResult = StringRegExp($sStr, "^(?i)[a-z0-9]*$") if $iResult Then Msgbox(0,"","Value OK") Else Msgbox(0,"","Value KO") EndIf Link to comment Share on other sites More sharing options...
Mat Posted July 4, 2013 Share Posted July 4, 2013 @Malkey, apologize ! i would meant "(?i)" for insensitive case as you say. so, corrected here, thanks $sStr = "fdaafsdfk#safa" $iResult = StringRegExp($sStr, "^(?i)[a-z0-9]*$") if $iResult Then Msgbox(0,"","Value OK") Else Msgbox(0,"","Value KO") EndIf Or Just: $sStr = "fdaafsdfk#safa" $iResult = StringRegExp($sStr, "^[A-z0-9]*$") if $iResult Then Msgbox(0,"","Value OK") Else Msgbox(0,"","Value KO") EndIf AutoIt Project Listing Link to comment Share on other sites More sharing options...
MyEarth Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) I'm confused, which one i need to use? For what i have understand: ^[A-z] is equal to [^a-zA-Z] Match any "word" character, lower or upper. Right? But what does mean: *$ I can't see nothing in the help about the dollar simbol Edited July 4, 2013 by MyEarth Link to comment Share on other sites More sharing options...
Mat Posted July 4, 2013 Share Posted July 4, 2013 (edited) I'm confused, which one i need to use? For what i have understand: ^[A-z] is equal to [^a-zA-Z] Match any "word" character, lower or upper. Right? But what does mean: *$ I can't see nothing in the help about the dollar simbol No, outside of [], ^ matches the start of the string. Word characters are A-z 0-9 and underscore Basically you are matching the start of the string (^), followed by zero or more (that's what the star does) alphanumeric characters ([A-z0-9], followed by the end of the string ($). This can only match if all the characters in the string are alphanumeric characters. Edited July 4, 2013 by Mat AutoIt Project Listing Link to comment Share on other sites More sharing options...
MyEarth Posted July 4, 2013 Author Share Posted July 4, 2013 Ok, understood. I'll check better the helpfile, for now i think i'll use the Malkey's script, i don't want to allow the underscore in the string Strange the point is a special char but the underscore not Link to comment Share on other sites More sharing options...
jchd Posted July 4, 2013 Share Posted July 4, 2013 Beware: [A-z] includes [ ] ^ _ ` which are not wanted IFUC. 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...
orbs Posted July 4, 2013 Share Posted July 4, 2013 underscore is not alpha-numeric and will make StringIsAlNum("_") return 0. try it. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
M4n0x Posted July 4, 2013 Share Posted July 4, 2013 underscore is not alpha-numeric and will make StringIsAlNum("_") return 0. try it. Correct, but if you try with special characters as "éèéàöüä" it doesn't work. Link to comment Share on other sites More sharing options...
orbs Posted July 4, 2013 Share Posted July 4, 2013 Correct, but if you try with special characters as "éèéàöüä" it doesn't work. these are alpha-numeric, although not in English. i doubt that the original intention of the requester is to exclude non-English strings. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
MyEarth Posted July 4, 2013 Author Share Posted July 4, 2013 (edited) Maybe i wasn't clear. I want a string with: 0123456789 abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ I want to avoid any special character and non printable character. I'm usign the Malkey's script and check the help of StringRegEx Edited July 4, 2013 by MyEarth Link to comment Share on other sites More sharing options...
AZJIO Posted July 4, 2013 Share Posted July 4, 2013 (edited) To do case insensitive '?do=embed' frameborder='0' data-embedContent>> Edited July 4, 2013 by AZJIO My other projects or all Link to comment Share on other sites More sharing options...
Malkey Posted July 5, 2013 Share Posted July 5, 2013 (edited) Here is a script to test all characters individually to see if they are special characters or not. ; Testing the StringIsAlNum() function ; A returns of "1" means all the characters in string being tested are only alphanumeric characters. ; A returns of "0" means a non-alphanumeric character is in the string being tested. ConsoleWrite("éèéàöüä returns " & StringIsAlNum("éèéàöüä") & @LF) ; returns 1 ; Note: The underscore character is not an alphanumeric character, contrary to what I said in Post #7. ConsoleWrite("---- StringIsAlNum() ----" & @LF) For $i = 0 To 255 ConsoleWrite(">" & $i & " = " & @TAB & "0x" & Hex($i, 2) & " " & ChrW($i) & @TAB & StringIsAlNum(ChrW($i)) & @LF) Next ConsoleWrite(@LF & "---- StringRegExp($string, '[^a-zA-Z0-9]') ----" & @LF) ; From post #7 For $i = 0 To 255 ConsoleWrite(">" & $i & " " & ChrW($i) & @TAB & StringRegExp(ChrW($i), '[^a-zA-Z0-9]') & @TAB & _ ; Returns "0" (False) if tested character is a-z, A-Z, or 0-9 (StringRegExp(ChrW($i), '[^a-zA-Z0-9]') = 0) & @LF) ; <------------------------------------ Returns "True" if tested character is a-z, A-Z, or 0-9 Next Hopefully you are using SciTE to run this script, as ConsoleWrite() displays in the lower output panel of the SciTE window. Edit: Added Note about StringIsAlNum() in script example. Edited July 5, 2013 by Malkey 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