avechuche Posted November 8, 2014 Share Posted November 8, 2014 (edited) First of all, sorry for my bad English I need 2 things, first I need to check a username supports only lowercase letters, uppercase and point. [.a-zA-Z] But I need that username, not start with it a period "." ^[^.][.a-zA-Z]+$ I have that expression, but not fully functional. 2) I need to check a number, but I need that number can not start with 0. I have this expression, but does not work very well ^[^0]d+$ Thx! Edited November 8, 2014 by avechuche Link to comment Share on other sites More sharing options...
Kyan Posted November 8, 2014 Share Posted November 8, 2014 (edited) 1) ^[^.][A-Za-z]+$ 2) ^[^0]d+$ Edited November 8, 2014 by Kyan avechuche 1 Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
avechuche Posted November 8, 2014 Author Share Posted November 8, 2014 1) ^[^.][A-Za-z]+$ 2) ^[^0]d+$ No 1) I replace the first expression by "^[a-zA-Z]+(.?[a-zA-Z]+)?$" and it works, but I think it can be smaller. 2) This expression is the same as mine, but it does not work. Link to comment Share on other sites More sharing options...
Kyan Posted November 8, 2014 Share Posted November 8, 2014 Forgot you wanted to match usernames with dots but without starting with a dot. Correction: ^[^.][.A-Za-z]+$ consolewrite("#1 '0321'=>"&StringRegExp("0321",'^[^0]\d+$')&@LF) consolewrite("#2 '321'=>"&StringRegExp("321",'^[^0]\d+$')&@LF) consolewrite("#3 '.usErname'=>"&StringRegExp(".usErname",'^[^\.][\.A-Za-z]+$')&@LF) consolewrite("#4 'usErname'=>"&StringRegExp("usErname",'^[^\.][\.A-Za-z]+$')&@LF) consolewrite("#5 'usErn.ame'=>"&StringRegExp("usErn.ame",'^[^\.][\.A-Za-z]+$')&@LF) If in front of "=>" is a "1" = it matched, if is a "0" = failed to match. Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
avechuche Posted November 8, 2014 Author Share Posted November 8, 2014 (edited) Forgot you wanted to match usernames with dots but without starting with a dot. Correction: ^[^.][.A-Za-z]+$ consolewrite("#1 '0321'=>"&StringRegExp("0321",'^[^0]\d+$')&@LF) consolewrite("#2 '321'=>"&StringRegExp("321",'^[^0]\d+$')&@LF) consolewrite("#3 '.usErname'=>"&StringRegExp(".usErname",'^[^\.][\.A-Za-z]+$')&@LF) consolewrite("#4 'usErname'=>"&StringRegExp("usErname",'^[^\.][\.A-Za-z]+$')&@LF) consolewrite("#5 'usErn.ame'=>"&StringRegExp("usErn.ame",'^[^\.][\.A-Za-z]+$')&@LF) If in front of "=>" is a "1" = it matched, if is a "0" = failed to match. Try this ConsoleWrite("#2 ' 0321'=>" & StringRegExp(" 0321", '^[^0]\d+$') & @LF) and ConsoleWrite("#5 'usErn.ame'=>" & StringRegExp("m", '^[^\.][\.A-Za-z]+$') & @LF) PD: Within [], no need to use "" to escape characters. Ex ==> [?] = [?] Edited November 8, 2014 by avechuche Link to comment Share on other sites More sharing options...
Kyan Posted November 8, 2014 Share Posted November 8, 2014 (edited) Forgot that kind of scenarios ^[^.]?[.A-Za-z]+$ ^[^0]?d+$ both will fail if a space is added, EDIT: those doesn't work since "?" is lazy, my bad for what you proposed this works ^[^.][.A-Za-z]+$ ^[^0]d+$ if you don't care about spaces being on your string ^[^.][.A-Za-zs]+$ [^0]?[ds]+$ ;Still mess up, it willl need lookahead RE Edited November 8, 2014 by Kyan Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
avechuche Posted November 8, 2014 Author Share Posted November 8, 2014 (edited) Forgot that kind of scenarios ^[^.]?[.A-Za-z]+$ ^[^0]?d+$ both will fail if a space is added, EDIT: those doesn't work since "?" is lazy, my bad for what you proposed this works ^[^.][.A-Za-z]+$ ^[^0]d+$ if you don't care about spaces being on your string ^[^.][.A-Za-zs]+$ [^0]?[ds]+$ ;Still mess up, it willl need lookahead RE The first was solved so "^[a-zA-Z]+(.[a-zA-Z]+)?$" ave.chuce ==> 1 avechuche ==> 1 .avechuche ==> 0 avechuche. ==> 0 [^0]?[ds]+$ It continues to resist. Edited November 8, 2014 by avechuche Link to comment Share on other sites More sharing options...
Kyan Posted November 8, 2014 Share Posted November 8, 2014 ConsoleWrite("#2 '321'=>" & StringRegExp(" 0321", '^[\s][^0][\d\s]+) & @LF) = 0 OK ConsoleWrite("#2 '321'=>" & StringRegExp("321", '^[\s][^0][\d\s]+) & @LF) = 0 BAD ConsoleWrite("#2 '321'=>" & StringRegExp("321", '^[\s]?[^0][\d\s]+$') & @LF) = 1 OK ConsoleWrite("#2 '321'=>" & StringRegExp(" 321", '^[\s]?[^0][\d\s]+$') & @LF) = 1 OK ConsoleWrite("#2 '321'=>" & StringRegExp(" 0321", '^[\s]?[^0][\d\s]+) & @LF) = 1 DEM BAD I guess I need some sleep, can't see what I'm doing wrong Heroes, there is no such thing One day I'll discover what IE.au3 has of special for so many users using it.C'mon there's InetRead and WinHTTP, way better Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 8, 2014 Moderators Share Posted November 8, 2014 I'm not sure why we are including spaces now... but you can add the "s" wherever you see fit. The neat thing about regex is that there are many ways to skin the cat. Here's a method that wasn't used: ConsoleWrite(( _ StringRegExp("01234", "^(?!0)\d+\z") _ = True) & @CRLF) ; fails as it should ConsoleWrite(( _ StringRegExp("12340", "^(?!0)\d+\z") _ = True) & @CRLF) ; succeeds as it should ConsoleWrite(( _ StringRegExp(".userName", "^(?i)(?!\.)[\.a-z]+\z") _ = True) & @CRLF) ; fails as it should ConsoleWrite(( _ StringRegExp("u.serName", "^(?i)(?!\.)[\.a-z]+\z") _ = True) & @CRLF) ; succeeds as it should Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
avechuche Posted November 8, 2014 Author Share Posted November 8, 2014 (edited) I'm not sure why we are including spaces now... but you can add the "s" wherever you see fit. The neat thing about regex is that there are many ways to skin the cat. Here's a method that wasn't used: ConsoleWrite(( _ StringRegExp("01234", "^(?!0)\d+\z") _ = True) & @CRLF) ; fails as it should ConsoleWrite(( _ StringRegExp("12340", "^(?!0)\d+\z") _ = True) & @CRLF) ; succeeds as it should ConsoleWrite(( _ StringRegExp(".userName", "^(?i)(?!\.)[\.a-z]+\z") _ = True) & @CRLF) ; fails as it should ConsoleWrite(( _ StringRegExp("u.serName", "^(?i)(?!\.)[\.a-z]+\z") _ = True) & @CRLF) ; succeeds as it should Great! You can add that you can not use a period at the end and I need to prevent two or more continuous point? avechuche. ==> False. ave..chuche ==> false Edited November 8, 2014 by avechuche Link to comment Share on other sites More sharing options...
jguinch Posted November 8, 2014 Share Posted November 8, 2014 (edited) For the first, you can try wiht this : "^[a-zA-Z]+(.[a-zA-Z]+)*$" or ^([[:alpha:]]+)(.(?1))*$ It should match something like User.Na.me, UserName .... For the second : "^[1-9]d*$" Edited November 8, 2014 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Malkey Posted November 8, 2014 Share Posted November 8, 2014 From the help file under 'Datatypes' we have, "A value 0 will be equal to Boolean False Any other number value will be equal to Boolean True." So in the example, if the first regex is true then the first regex does not equal zero.. Therefore, the first expression 'regex <> 0' is true. If the second regex is false (meaning there are no two dots next to each other) then the second regex equals zero. Therefore, the second expression 'regex = 0' is true. Now when the first 'regex <> 0' is True And the second 'regex = 0' is true the outcome of the two expressions combined with And is true If either or both expressions are false then the combined outcome is false. Local $aList[4] = ["u.serName", ".userName", "userName.", "u..serName"] For $i = 0 To UBound($aList) - 1 ConsoleWrite(((StringRegExp($aList[$i], "^(?i)(?!\.)[\.a-z]+(?<!\.)\z") <> 0) And _ (StringRegExp($aList[$i], "\.\.") = 0)) & @TAB & $aList[$i] & @CRLF) Next #cs Returns :- True u.serName False .userName False userName. False u..serName #ce Link to comment Share on other sites More sharing options...
mikell Posted November 9, 2014 Share Posted November 9, 2014 (edited) One expression (jguinch's one) should suffice Local $aList[6] = ["userName", "u.serName", "u.ser.Name", ".userName", "userName.", "u..serName"] For $i = 0 To UBound($aList) - 1 ConsoleWrite(StringRegExp($aList[$i], '(?i)^([a-z]+)(\.(?1))*$' ) & @TAB & $aList[$i] & @CRLF) Next Edited November 9, 2014 by mikell Link to comment Share on other sites More sharing options...
jguinch Posted November 9, 2014 Share Posted November 9, 2014 @mikell : I think the "?" is not useful. Why did you add it ? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted November 9, 2014 Share Posted November 9, 2014 It is not. Its a remnant from an other try, sorry Edited Link to comment Share on other sites More sharing options...
Solution avechuche Posted November 9, 2014 Author Solution Share Posted November 9, 2014 Thank you all, this is the final expression. Local $aList[7] = ["userName", "u.serName", "u.ser.Name", ".userName", "userName.", "u..serName", "aaa.bbb"] For $i = 0 To UBound($aList) - 1 ConsoleWrite(StringRegExp($aList[$i], '(?i)^([a-z]+)(\.(?1))?$' ) & @TAB & $aList[$i] & @CRLF) Next 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