> Rick Bragg wrote: > > Hi, > > > > I want to write a script that will test the contents of a file. > > > > The file being tested will pass only if it contains nothing more than an > > ip address on one line. Does anyone have a sample of a simple regex to > > accomplish this? > > /\d+\.\d+\.\d+\.\d+\n?/s >
Beware of insufficient regexes in regex clothing. The above will certainly find one or more digits followed by a dot, followed by one or more digits followed by a dot, etc. But it does *NOT* match an IP address... /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ Is at least closer, but it is still not sufficient, as IP addresses are bounded, I believe, at 255 so 336.47.894.0, will match the above, but is not a valid IP address. How strict do you need to be, how sure are you about the data in the files? http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]