[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about a regular expression

Diego Amicabile

7/22/2006 12:52:00 PM

Hi fellow ruby-ers

I don't understand this regular expression

/\S+ </

It is from the ruby quiz "Secret Santas"

http://www.rubyquiz.com/...

What does it exactly mean ? The "<" confuses me

Greetings & Thanks

--
Posted via http://www.ruby-....

2 Answers

ts

7/22/2006 1:05:00 PM

0

>>>>> "D" == Diego Amicabile <diegoami@web.de> writes:

D> /\S+ </

Well the format for a line is

FIRST_NAME space FAMILY_NAME space <EMAIL_ADDRESS> newline

The regexp will select any non-whitespace character followed by a space and
the character <

'<' was added to extract the FAMILY_NAME, without this character
(i.e. with /\S+ /) the regexp will match FIRST_NAME


Guy Decoux






Matthew Smillie

7/22/2006 1:23:00 PM

0

On Jul 22, 2006, at 13:51, Diego Amicabile wrote:

> Hi fellow ruby-ers
>
> I don't understand this regular expression
>
> /\S+ </
>
> It is from the ruby quiz "Secret Santas"
>
> http://www.rubyquiz.com/...
>
> What does it exactly mean ? The "<" confuses me

In this case, the '<' is just a character. So, it's looking for a
series of one or more non-whitespace characters, followed by a space,
followed by a '<'

/\S+ </.match("blah match_this_section < but not this")[0]
=> "match_this_section <"

matthew smillie.