Parsing / Extracting Text from String in Rails?
Posted
by
user641116
on Stack Overflow
See other posts from Stack Overflow
or by user641116
Published on 2011-06-25T00:30:47Z
Indexed on
2011/06/25
8:22 UTC
Read the original article
Hit count: 401
I have a string in Rails, e.g. "This is a Twitter message. #books War & Peace by Leo Tolstoy. I love this book!", and I want to parse the text and extract only certain phrases, like "War & Peace by Leo Tolstoy".
Is this a matter of using Regex and lifting the text between "#books" to "."?
What if there's no structure to the message, like: "This is a Twitter message #books War & Peace by Leo Tolstoy I love this book!" or "This is a Twitter message. I love the book War & Peace by Leo Tolstoy #books" How can I reliably pull the phrase "War & Peace by Leo Tolstoy" without knowing the phrase ex ante.
Are there any gems, methods, etc. that can help me do this?
At the very least, what would you call what I'm trying to do? It will help me search for a solution on Google. I've tried a few searches on "parsing" with no luck.
© Stack Overflow or respective owner