Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Finding your match with Ruby (See related posts)

This example finds an email subject in a string and passes the value to a variable called 'subject'.
subject = (/^Subject\: (.+)$/).match(email)[1]

Prior to this code I would have used the following:
  email[/^Subject\: (.+)$/]
  subject = $1

Reference: Ruby SMTP Server - Save to Database [dzone.com]

Comments on this post

ChronicStar posts on Feb 20, 2008 at 22:23
What about:

subject = email[/^Subject\: (.+)$/, 1]


Essentially the same as your second snippet but in one line and without the global, which I assume were your problems with it?
jrobertson posts on Feb 21, 2008 at 05:47
Great! that's another new pattern match I've learnt!

You need to create an account or log in to post comments to this site.


Click here to browse all 4834 code snippets

Related Posts