From: Edward QU Date: 2012-06-17T13:20:50+09:00 Subject: regular expression to get IPCONFIG information Dear all I want to use ruby regular expression to get ipconfig information from a string. I wrote some code, but it is not works well. would anybody help me, thanks! the coding is like that $msdos="ipconfig /all" str_ipcfg=eval("`"+$msdos+"`") str_ipcfg.scan %r{ ^ \S [^:]* : \s* $ (?: ^ \s+ [^:]+ : [^:]+ $ [\n\r]+ )* }x do |adapter| p adapter 1. if use $msdos="ipconfig", get a string like the following: "Windows IP Configuration\n\n\nWireless LAN adapter 2:\n\n Media State . . . . . . . . . . . : Media disconnected\n Connection-specific DNS Suffix . : \n\n" "Ethernet adapter Bluetooth :\n\n Media State . . . . . . . . . . . : Media disconnected\n Connection-specific DNS Suffix . : \n\n" "Wireless LAN adapter :\n\n Connection-specific DNS Suffix . : \n IPv4 Address. . . . . . . . . . . : 192.168.1.50\n Subnet Mask . . . . . . . . . . . : 255.255.255.0\n Default Gateway . . . . . . . . . : 192.168.1.1\n" Process finished with exit code 0 2. if use "$msdos="ipconfig /all", the string like that: "Wireless LAN adapter 2:\n\n Media State . . . . . . . . . . . : Media disconnected\n Connection-specific DNS Suffix . : \n Description . . . . . . . . . . . : Microsoft Virtual WiFi Miniport Adapter\n Physical Address. . . . . . . . . : 16-2F-68-CB-81-37\n DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled . . . . : Yes\n\n" "Ethernet adapter Bluetooth :\n\n Media State . . . . . . . . . . . : Media disconnected\n Connection-specific DNS Suffix . : \n Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)\n Physical Address. . . . . . . . . : 74-2F-68-CC-41-BF\n DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled . . . . : Yes\n\n" "Wireless LAN adapter :\n\n Connection-specific DNS Suffix . : \n Description . . . . . . . . . . . : Atheros AR9485WB-EG Wireless Network Adapter\n Physical Address. . . . . . . . . : 74-2F-68-CB-81-37\n DHCP Enabled. . . . . . . . . . . : Yes\n Autoconfiguration Enabled . . . . : Yes\n IPv4 Address. . . . . . . . . . . : 192.168.1.50(Preferred) \n Subnet Mask . . . . . . . . . . . : 255.255.255.0\n" my question is : where is wrong in my 2ed regular express, causing the string is not complete, i could not get the whole ipconfig information? because the gateway, dhcp, dns information is after the subnet mask information. many thanks! Have a nice day. Edward -- Posted via http://www.ruby-forum.com/.