Ghost1982 Posted February 18, 2020 Share Posted February 18, 2020 Hello, I was wondering if it's possible to somehow display the pattern that DOESN'T follow the regex pattern from string. So it scans the string according to pattern, detects that it's wrong and additionally display the wrong part of name. Let's say I have a ReGex that scans the website address www.some_address.com (?i) ((www\.) ([0-9a-z]{1,}) (\.com$) When someone enters www.some_address.NET or ww.some_address.com, I would like to display MsgBox or SplashTextOn text field with message: "Address cannot end with NET" or "Address cannot start with ww." Link to comment Share on other sites More sharing options...
Neutro Posted February 18, 2020 Share Posted February 18, 2020 (edited) Hello, Functions will do what they are designed to do so you can't make them do something else However, you can use StringLeft and StringRight functions to get the first 4 characters, see if they match "www." and the last 4 to see if they match ".com". Also if you explain us what you're trying to achieve with your script using that url, maybe we can help you better Edited February 18, 2020 by Neutro Identify active network connections and change DNS server - Easily export Windows network settings Clean temporary files from Windows users profiles directories - List Active Directory Groups members Export content of an Outlook mailbox to a PST file - File patch manager - IRC chat connect example Thanks again for your help Water! Link to comment Share on other sites More sharing options...
seadoggie01 Posted February 18, 2020 Share Posted February 18, 2020 Basically a regular expression checks if something matches or not. To verify if three different parts match, you'll probably need to use multiple regular expressions. In this case, I would break it up into sections: ValidateWebsite("ww.some_.address.net") ValidateWebsite("www.some_.address.net") ValidateWebsite("www.some_.address.com") ValidateWebsite("www.some_address.com") Func ValidateWebsite($sWebsite) ; If the website doesn't start with www. If Not StringRegExp($sWebsite, "(?im)^www\..*") Then ConsoleWrite("Fail 1" & @CRLF) ; If the website doesn't end with .com ElseIf Not StringRegExp($sWebsite, "(?i)^www\..*\.com$") Then ConsoleWrite("Fail 2" & @CRLF) ; If the website doesn't match in the middle ElseIf Not StringRegExp($sWebsite, "(?i)^www\.[^.]+\.com$") Then ConsoleWrite("Fail 3" & @CRLF) Else ConsoleWrite("Correct" & @CRLF) EndIf EndFunc A few points on your RegEx: {1,} is the same as + You have an extra opening parenthesis and extra spaces (I think this is due to copy-paste) [0-9a-z]+ doesn't match some_address, you probably want to match everything except periods: [^.]+ All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Ghost1982 Posted February 18, 2020 Author Share Posted February 18, 2020 2 hours ago, seadoggie01 said: Basically a regular expression checks if something matches or not. To verify if three different parts match, you'll probably need to use multiple regular expressions. In this case, I would break it up into sections: ValidateWebsite("ww.some_.address.net") ValidateWebsite("www.some_.address.net") ValidateWebsite("www.some_.address.com") ValidateWebsite("www.some_address.com") Func ValidateWebsite($sWebsite) ; If the website doesn't start with www. If Not StringRegExp($sWebsite, "(?im)^www\..*") Then ConsoleWrite("Fail 1" & @CRLF) ; If the website doesn't end with .com ElseIf Not StringRegExp($sWebsite, "(?i)^www\..*\.com$") Then ConsoleWrite("Fail 2" & @CRLF) ; If the website doesn't match in the middle ElseIf Not StringRegExp($sWebsite, "(?i)^www\.[^.]+\.com$") Then ConsoleWrite("Fail 3" & @CRLF) Else ConsoleWrite("Correct" & @CRLF) EndIf EndFunc A few points on your RegEx: {1,} is the same as + You have an extra opening parenthesis and extra spaces (I think this is due to copy-paste) [0-9a-z]+ doesn't match some_address, you probably want to match everything except periods: [^.]+ Hello Thanks. This will be helpful. I know there may be errors in my RegEx. I was just writing it from my head without compiling. What I'm trying to achieve is to make some pop up with information for user what is wrong in the string and to type it again properly. We never know what can be typed incorrectly by someone but I'd like to show that particualr incorrect part of address that was entered. Not only ".net" or "ww". Link to comment Share on other sites More sharing options...
Nine Posted February 18, 2020 Share Posted February 18, 2020 The absolute way to test for a valid URL is : #include <Constants.au3> MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https://www.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https;//www.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("http://www.autoitscript.net/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https://ww.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) Func _IsValidURL ($sURL) Return InetGetSize ($sURL) > 0 EndFunc seadoggie01 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Ghost1982 Posted February 18, 2020 Author Share Posted February 18, 2020 1 hour ago, Nine said: The absolute way to test for a valid URL is : #include <Constants.au3> MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https://www.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https;//www.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("http://www.autoitscript.net/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) MsgBox ($MB_SYSTEMMODAL,"",_IsValidURL ("https://ww.autoitscript.com/forum/topic/201773-regex-display-string-that-doesnt-match-a-pattern/")) Func _IsValidURL ($sURL) Return InetGetSize ($sURL) > 0 EndFunc But here we're still analysing only "ww" or "net". These were just example strings that someone can enter. Someone may also type w.autoitscript.com or abc.autoitscript.xyz or anything else. What I'm trying to achievie is to display ANY wrong part of the string. So the ONLY correct address in this case is www.autoitscript.com. If any part of it is mispelled I'd like to display this "wrong part" that DOESN'T match the RegEx pattern. Is it possible? Link to comment Share on other sites More sharing options...
seadoggie01 Posted February 18, 2020 Share Posted February 18, 2020 If you break up the task, kind of, as I showed... but you won't really know, as garbage in = garbage out 😐 You can check the smaller pieces with a regular expression, but the real way to know is to try All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
mikell Posted February 18, 2020 Share Posted February 18, 2020 4 hours ago, Ghost1982 said: What I'm trying to achieve is to make some pop up with information for user what is wrong in the string Regex is a good way. You might use it first to split the address to an array and then successively check the array elements to build the error message(s) #Include <Array.au3> $str = "www.so.me_add.ress.com" $r = StringRegExp($str, '^(\w+)\.(.+)\.(\w+)$', 3) _ArrayDisplay($r) Link to comment Share on other sites More sharing options...
iamtheky Posted February 19, 2020 Share Posted February 19, 2020 (edited) if you have all the rules, you could also SRER the matches to blanks, leaving only the wrong portion... edit: is it just 3 w's and ends in .com? just refining this behavior? $err = "" ;~ $str = "www.so.me_add.ress.com" ;~ $str = "www.so.me_add.ress.net" $str = "w3.so.me_add.ress.org" If stringleft($str , 4) <> "www." Then $err &= stringleft($str , stringinstr($str , ".")) & @CRLF If stringright($str , 4) <> ".com" Then $err &= stringright($str , 4) $err <> "" ? msgbox(0, 'error' , $err) : msgbox(0, 'Good' , $str) Edited February 19, 2020 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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