Question about a regular expression

T

ts

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
 
M

Matthew Smillie

Hi fellow ruby-ers

I don't understand this regular expression

/\S+ </

It is from the ruby quiz "Secret Santas"

http://www.rubyquiz.com/quiz2.html

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,812
Messages
2,569,694
Members
45,478
Latest member
dontilydondon

Latest Threads

Top