Juanola Posted February 17, 2009 Share Posted February 17, 2009 I use the pattern: '(\d{1,3}\.){3}\d{1,3}:[0-9]{5}|(\w\.){2}\w:[0-9]{5}' for find strings as: 192.45.234.1:66000 192.168.122.322:74000 san4.ukr.net:32000 ............. ............. But stringregexp isn't finding nothing. Is my pattern ok? Thank you! Link to comment Share on other sites More sharing options...
Xand3r Posted February 17, 2009 Share Posted February 17, 2009 (edited) #include<array.au3> $reg=StringRegExp("127.0.0.1:67776","([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:([0-9]{1,5})",3) _ArrayDisplay($reg) Edited February 17, 2009 by TheMadman Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro Link to comment Share on other sites More sharing options...
Juanola Posted February 17, 2009 Author Share Posted February 17, 2009 (edited) #include<array.au3> $reg=StringRegExp("127.0.0.1:67776","([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:([0-9]{1,5})",3) _ArrayDisplay($reg) Thank you!!! But and the string "san4.ukr.net:32000" ? My pattern is bad? I think what my pattern is OK. Edited February 17, 2009 by Juanola Link to comment Share on other sites More sharing options...
Bowmore Posted February 17, 2009 Share Posted February 17, 2009 Two examples from RegexBuddy IP address (accurate capture) Matches 0.0.0.0 through 255.255.255.255 Use this regex to match IP numbers with accurracy. Each of the 4 numbers is stored into a capturing group, so you can access them for further processing. "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b"oÝ÷ ØÚuÚÞ²ÆrêÚµãµÈ^³M4ÒØk¢è!Ûvç¹çnyRÇ++z±¶µÈH>{¦mêìÂ+aiÇ.®¶ËiDzËh¶¢Ø¯ÛçºfޮƮ¶sbgV÷C²b3#²b3#¶"ó¢ó£#U³ÓU×Ã%³ÓEÕ³Ó×ųÓõ³ÓÕ³ÓÓòb3#²b3#²â³7Òó£#U³ÓU×Ã%³ÓEÕ³Ó×ųÓõ³ÓÕ³ÓÓòb3#²b3#¶"gV÷C "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Juanola Posted February 17, 2009 Author Share Posted February 17, 2009 (edited) Thank you!! It is one great and professional answer, but I want find IP with numbers and with letters. I want too find IP's as: san4.ukr.net:32000 Your pattern find IP's as 192.168.22.111 But I too want find IP's as "san4.ukr.net:32000" |(\w\.){2}\w:[0-9]{5}' OR san4.ukr.net:32000 Is my pattern bad? Why I can't find nothing with my pattern? '(\d{1,3}\.){3}\d{1,3}:[0-9]{5}|(\w\.){2}\w:[0-9]{5}' Thank you!!! Edited February 17, 2009 by Juanola Link to comment Share on other sites More sharing options...
martin Posted February 17, 2009 Share Posted February 17, 2009 Thank you!! It is one great and professional answer, but I want find IP with numbers and with letters. I want too find IP's as: san4.ukr.net:32000 Your pattern find IP's as 192.168.22.111 But I too want find IP's as "san4.ukr.net:32000" |(\w\.){2}\w:[0-9]{5}' OR san4.ukr.net:32000 Is my pattern bad? Why I can't find nothing with my pattern? '(\d{1,3}\.){3}\d{1,3}:[0-9]{5}|(\w\.){2}\w:[0-9]{5}' Thank you!!! I don't see anything wrong with your pattern except that it doesn't work. This works though $test = '((\d{1,3}\.){3}\d{1,3}:[0-9]{4,6})|\w*\.\w*\.\w*:[0-9]{5}' $s = "san4.ukr.net:32000" $r = stringregexp($s,$test,1) ConsoleWrite($r[0] & @CRLF) $s = "192.45.234.1:66000" $r = stringregexp($s,$test,1) ConsoleWrite($r[0] & @CRLF) I tried a lot of combinations with groups and repeating characters but it seems that when you use the OR symbol a lot of things after the OR symbol don't work as you would expect, or there is something we don't understand. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 18, 2009 Share Posted February 18, 2009 I think one of the problems is noone is escaping the ':'s, the other is probably that \w doesn't seem to catch words with numbers in them? In any case, this seems to works from my tests: $sString="192.45.234.1:66000" & @CRLF & "192.168.122.322:74000" & @CRLF & "san4.ukr.net:32000" $aIPArray=StringRegExp($sString,"((?:\d{1,3}\.){3}\d{1,3}\:[0-9]{5}|(?:[[:alnum:]]+\b\.){2}[[:alnum:]]+\b\:[0-9]{5})",3) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Authenticity Posted February 18, 2009 Share Posted February 18, 2009 lol, Do you aware that this pattern match insane IP addresses as well? $sString="192.45.234.109090909090:66000" & @CRLF & "192.168.122.3226923212yy312123a:74000" & @CRLF & "san4.ukr.net:32000" You should not use greedy quantifiers if they will match through the whole string part and backtrack to a valid spot where it can match unwanted stuff. You don't have to preform it all in one line... Link to comment Share on other sites More sharing options...
Ascend4nt Posted February 18, 2009 Share Posted February 18, 2009 lol, Do you aware that this pattern match insane IP addresses as well? $sString="192.45.234.109090909090:66000" & @CRLF & "192.168.122.3226923212yy312123a:74000" & @CRLF & "san4.ukr.net:32000" You should not use greedy quantifiers if they will match through the whole string part and backtrack to a valid spot where it can match unwanted stuff. You don't have to preform it all in one line... I didn't see those types of strings in the example provided, nor did Juanolo indicate if there were invalid IP strings in whatever they are checking. Sure, Juanola can get an array of # IP addresses first, but how do you propose a solution for websites that *can* contain many of those crazy strings. Should it end in official '.com,.net, and a million other top-level domains'? That would be one long string. Maybe if Juanola could narrow down what top-level domain names, the end can be a simple \.(net|com|org)\:\d{5} My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
Authenticity Posted February 18, 2009 Share Posted February 18, 2009 Probably it can take time although the solution is obvious and a short search might come up with a fast solution. About the hostpath and the top-level domain it's not a task for RegEx alone as it's require an external resource like a csv file that contain the valid 2 letters country code and the .info, .com, .org, .mail is quite limited for this purpose so it can be examined using alternations. Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 18, 2009 Share Posted February 18, 2009 What you are actually looking for is a hostname match and a port number. IP addresses are dotted quads (0.0.0.0). When you want to match words, there's nothing you can do to stop it from matching crazy IP addresses. Link to comment Share on other sites More sharing options...
TerarinK Posted February 18, 2009 Share Posted February 18, 2009 Correct me if I'm wrong but ping-ing the number first off then doing your check will comeout with a number form instead of alpha-numerical 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E Link to comment Share on other sites More sharing options...
Richard Robertson Posted February 18, 2009 Share Posted February 18, 2009 It would be better to just run the passed entry to a DNS server. It will return an IP address for a hostname, and for an IP address. Link to comment Share on other sites More sharing options...
Malkey Posted February 18, 2009 Share Posted February 18, 2009 I use the pattern: '(\d{1,3}\.){3}\d{1,3}:[0-9]{5}|(\w\.){2}\w:[0-9]{5}' for find strings as: 192.45.234.1:66000 192.168.122.322:74000 san4.ukr.net:32000 ............. ............. But stringregexp isn't finding nothing. Is my pattern ok? Thank you! This appears to work. #include<array.au3> $sString = "192.45.234.1:66000 192.168.122.322:74000 san4.ukr.net:32000" & @CRLF & "san4.ukr.net:32000" $reg = StringRegExp($sString, "((?:\w{1,3}\.\w{1,3}\.\w{1,3}\.\w{1,3}:\w{5})|(?:\w{1,}\.\w{1,}\.\w{1,}:\w{5}))", 3) _ArrayDisplay($reg) Link to comment Share on other sites More sharing options...
TerarinK Posted February 18, 2009 Share Posted February 18, 2009 what about if you have microsoft.net:30126 that would not do it, you would need a numerical number such as 207.46.197.32:30126 as that applies to microsoft.net. You need to pass the whole address into probably a string and dll call winnet for a change in you address to ensure it is numerical else it will error out 0x576520616C6C206469652C206C697665206C69666520617320696620796F75207765726520696E20746865206C617374207365636F6E642E Link to comment Share on other sites More sharing options...
Malkey Posted February 18, 2009 Share Posted February 18, 2009 what about if you have microsoft.net:30126 that would not do it, you would need a numerical number such as 207.46.197.32:30126 as that applies to microsoft.net. You need to pass the whole address into probably a string and dll call winnet for a change in you address to ensure it is numerical else it will error outSo are you saying this one would not work either? #include<array.au3> $sString = "A list of IP's :- 192.45.234.1:66000 192.168.122.322:74000 san4.ukr.net:32000" & @CRLF & _ "san4.ukr.net:32000 and another, microsoft.net:30126 and that is all." $reg = StringRegExp($sString, "([\w+\.]+:\w{5})", 3) _ArrayDisplay($reg) 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