From: Timothy Hunter Date: 2005-12-24T00:02:52+09:00 Subject: Re: Quick Regex Query Neowulf wrote: > Hi all, > > Really quick one for the regex gurus... > > Anyone know of a regex string which will extract out the stuff between > "from" and "not" without the spaces between? > > User root from toronto-hs-216-138-233-211.s-ip.magma.ca not allowed > because not listed in AllowUsers > > I've found something which *almost* does the job... > > \bfrom\W+(?:\w+\W+){1,6}not\b > > This is limited however, as I can't know for certain how many "words" > will make up the hostname. > > I've got a non-regex solution already, but you don't want to know how > that one works... > > ... something to do with using split and relying on the fact that the > host name field always end up at the same index. > > Seems more than a little clunky. > > Any advise appreciated. > > Cheers > > ~Neowulf > str = "User root from toronto-hs-216-138-233-211.s-ip.magma.ca not allowed because not listed in AllowUsers" m = /from (.*?) not/.match(str) puts m[1]