Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Quick Regex Query

Reply
Thread Tools

Quick Regex Query

 
 
Neowulf
Guest
Posts: n/a
 
      12-23-2005
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

 
Reply With Quote
 
 
 
 
it_says_BALLS_on_your_forehead
Guest
Posts: n/a
 
      12-23-2005

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.


why do the number of words matter? i thought you only needed the
'stuff' between 'from' and 'not'. now when you say 'without the spaces
between', do you mean the spaces immediately after the from, and before
the not? what's wrong with:

/from\s+(\w+)\s+not/ && print "$1" # i'm more familiar with Perl, not
sure if $1 works in
# ruby, but it
should contain what's in capturing parens

can you provide several examples of input and expected output that
would illustrate your requirements?

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-23-2005
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


host_name = /from\s+(\S+)\s+not/ =~ s && $1

> This is limited however, as I can't know for certain how many "words"
> will make up the hostname.


But there won't be any whitespace in the hostname, right? Then the RX
above will do it.

Kind regards

robert

 
Reply With Quote
 
Florian Groß
Guest
Posts: n/a
 
      12-23-2005
Robert Klemme wrote:

> host_name = /from\s+(\S+)\s+not/ =~ s && $1


Tsk, those Perl guys...

host_name[/from\s+(\S+)\s+not/, 1] # Will either return nil or a String

--
http://flgr.0x42.net/



 
Reply With Quote
 
Neowulf
Guest
Posts: n/a
 
      12-23-2005
Thanks Guys,

Top effort all round.

Regex gives me a serious head ache sometimes...

Thanks again everyone for the help.

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      12-27-2005
Florian Groß <(E-Mail Removed)> wrote:
> Robert Klemme wrote:
>
>> host_name = /from\s+(\S+)\s+not/ =~ s && $1

>
> Tsk, those Perl guys...


Ssshhh! I'm trying to get over my Perl heritage but sometimes it still
haunts me...

> host_name[/from\s+(\S+)\s+not/, 1] # Will either return nil or a
> String


Thanks for reminding me - I always keep forgetting this variant, especially
with the group selector!

Kind regards

robert


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Adding quick-release to a non-quick-release tripod head ste7esmith@hotmail.com Digital Photography 4 11-20-2006 03:19 PM
Quick Question Quick Answer JKop C++ 11 05-24-2004 09:46 PM
Quick Restore for a Compaq not so quick! Croos Bustamunky Computer Support 2 05-15-2004 04:17 AM
PanasonicBQ390 "quick" charger - How quick? Ol' Bab Digital Photography 1 01-17-2004 06:54 AM



Advertisments