Simple - using String # scan to retrieve an email address
I have a line containing:
@from = "John Doe <john.doe@daemon.co.uk>"
When I do this:
@from.scan('/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i')
I am not getting any results. I am trying to extract the email address myself.
I tried to delete \ b, but that didn't work either.
Any help would be greatly appreciated.
Your expression works just fine: rubular
The problem is that the quotation marks around your regular expression mean that it is interpreted as a simple text string, not a regular expression. Removing quotes solves the problem: ideone
@from = "John Doe <john.doe@daemon.co.uk>"
@from.scan(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i) { |x| puts x }
Conclusion:
john.doe@daemon.co.uk