steelsking Posted August 12, 2011 Share Posted August 12, 2011 hi everyone, i am very confused on using the StringReg Exp function. how do i strip thw following 172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 to this 172.17.153.7 CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 thank you! Link to comment Share on other sites More sharing options...
GEOSoft Posted August 12, 2011 Share Posted August 12, 2011 $s_Str = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" $s_Rtn = StringRegExpReplace($s_Str, "((25[0-4]|(2[0-4]|1[0-9]|[1-9]?)[0-9]\.){3}(25[0-4]|(2[0-4]|1[0-9]|[1-9]?)[0-9])\h+).*?%(.+)", "$1$6") MsgBox(0, "Result", $s_Rtn) George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Newb Posted August 12, 2011 Share Posted August 12, 2011 There is any guide on autoit reg exp? I just tried with help file and some selfmade code but got nothing... I know a little about reg exping in some other language but when I get into trying here in autoit the output is always blank or 0. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
steelsking Posted August 12, 2011 Author Share Posted August 12, 2011 Hi GeoSoft, thanks for the codes. however, is there any simpler way of doing this? will the codes work on other lines? thanks. Link to comment Share on other sites More sharing options...
Malkey Posted August 12, 2011 Share Posted August 12, 2011 Here is an example of some code working on other lines. Local $str = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "169.17.154.8 2011 Aug 12 11:00:10 SIN +08:00 %CUP-5-NVLANMISMATCH:Native vlan mismatch detected on port 2/5" ConsoleWrite(StringRegExpReplace($str, "(\d{4} [[:alpha:]]{3}.*? %)", "") & @LF) ; The RE pattern, "(\d{4}.*? %)", matches 4 digits, followed by space, then at least 3 letters, followed by all characters up ; to and including the first "space%" characters that are encountered. All those matched characters are then replaced ; with "", which is nothing. ; ; So everything between "4 digits, a space, and 3 letters" and ending with "a space and %", inclusive, is deleted. ; Returns:- ; 172.17.153.7 CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 ; 169.17.154.8 CUP-5-NVLANMISMATCH:Native vlan mismatch detected on port 2/5 @Newb If you are using StringRegExp() function and you don't know an array is returned, this would explain why a blank is always returned. See "Flag" parameter in help file under StringRegExp. Otherwise, it may be best to start your own topic. Link to comment Share on other sites More sharing options...
wakillon Posted August 12, 2011 Share Posted August 12, 2011 There is any guide on autoit reg exp?I just tried with help file and some selfmade code but got nothing...I know a little about reg exping in some other language but when I get into trying here in autoit the output is always blank or 0.Look here. AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
UEZ Posted August 12, 2011 Share Posted August 12, 2011 Here my version: $input = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" MsgBox(0, "RegEx", StringRegExpReplace($input, "(?i)([\d+]{4} [a-z]{3} [\d+]{2}.*%)", "")) Br, 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...
GEOSoft Posted August 12, 2011 Share Posted August 12, 2011 That works Uez. Often it easier to take out what you don't want and leave the rest.@steelskingI have several ip validator expressions and I just grabbed the first one from the list then added what I needed to thatUEZs method is probably the easiest one providing you are sure the ip address is valid. Mine validates the ip as well as adding the potion after the %Malkeys should also be good.This is one of the big benefits of RegEx; flexibility. You can achieve the same results using several methods. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
steelsking Posted August 16, 2011 Author Share Posted August 16, 2011 thank you guys for all the help and detailed explanation!!! Link to comment Share on other sites More sharing options...
steelsking Posted August 17, 2011 Author Share Posted August 17, 2011 (edited) hi guys, sorry, i hit into a problem. the following line is parsed correctly from this 172.17.112.6 2008 Jan 14 00:02:17 SIN +08:00 %DTP-5-TRUNKPORTON:Port 6/44 has become isl trunk to 172.17.112.6 DTP-5-TRUNKPORTON:Port 6/44 has become isl trunk but these lines do not. 172.17.175.129 55182: Jan 14 00:05:38: %LANCE-5-LATECOLL: Unit 0, late collision error to 172.17.175.129 LANCE-5-LATECOLL: Unit 0, late collision error kindly assist please. thank you very much! Edited August 17, 2011 by steelsking Link to comment Share on other sites More sharing options...
Malkey Posted August 17, 2011 Share Posted August 17, 2011 Try this. Local $str = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "172.17.175.129 55182: Jan 14 00:05:38: %LANCE-5-LATECOLL: Unit 0, late collision error" & @CRLF & _ "169.17.154.8 2011 Aug 12 11:00:10 SIN +08:00 %CUP-5-NVLANMISMATCH:Native vlan mismatch detected on port 2/5" ConsoleWrite(StringRegExpReplace($str, "(?i)(\d{4,}:? [a-z]{3}.*? %)", "") & @LF) ; The part RE pattern, "\d{4,5}:?", matches 4 or more digits, followed by a ":" or not. So now, the start of the captured group will begin with ; either 4 or more digits may be, may be not followed by a ":". That is, in the example the matching groups start with 2008, 55182: and 2011. ; ; Returned:- ; 172.17.153.7 CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6 ; 172.17.175.129 LANCE-5-LATECOLL: Unit 0, late collision error ; 169.17.154.8 CUP-5-NVLANMISMATCH:Native vlan mismatch detected on port 2/5 Link to comment Share on other sites More sharing options...
steelsking Posted August 17, 2011 Author Share Posted August 17, 2011 thanks for the help Malkey. but as I went thru the logs file, it failed to parse the following lines correctly. 172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down 172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down to 172.17.183.134 LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down 172.17.174.134 LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down please help me. thanks once again! Link to comment Share on other sites More sharing options...
UEZ Posted August 17, 2011 Share Posted August 17, 2011 (edited) Try this one: $string = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down" & @CRLF & _ "172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down" $filter = StringRegExpReplace($string, "(\d+\.\d+\.\d+\.\d+ )(.*%)", "$1") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $filter = ' & @CRLF & $filter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console MsgBox(0, "RegEx", $filter) Br, UEZ Edited August 17, 2011 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...
steelsking Posted August 17, 2011 Author Share Posted August 17, 2011 thanks UEZ! work very well, but just one more little issue. $string = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down" & @CRLF & _ "172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down" & @CRLF & _ "172.17.174.1 13: Cisco Internetwork Operating System Software" $filter = StringRegExpReplace($string, "(\d+\.\d+\.\d+\.\d+ )(.*%)", "$1") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $filter = ' & @CRLF & $filter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console MsgBox(0, "RegEx", $filter) Thanks! Link to comment Share on other sites More sharing options...
UEZ Posted August 17, 2011 Share Posted August 17, 2011 And this one? $string = "172.17.153.7 2008 Jan 14 06:57:02 SIN +08:00 %CDP-4-NVLANMISMATCH:Native vlan mismatch detected on port 3/6" & @CRLF & _ "172.17.183.134 17: 07:45:48: %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/13, changed state to down" & @CRLF & _ "172.17.174.134 4303: 2y14w: %LINK-3-UPDOWN: Interface FastEthernet0/7, changed state to down" & @CRLF & _ "172.17.174.1 13: Cisco Internetwork Operating System Software" $filter = StringRegExpReplace($string, "(\d+\.\d+\.\d+\.\d+ )(.*%|.*\d+: )", "$1") ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $filter = ' & @CRLF & $filter & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console MsgBox(0, "RegEx", $filter) Br, 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...
steelsking Posted August 17, 2011 Author Share Posted August 17, 2011 "172.17.174.1 13: Cisco Internetwork Operating System Software" to "172.17.174.1 Cisco Internetwork Operating System Software" pls take note that this number cd be single digit or more. thanks UEZ! 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