AnApprentice
AnApprentice

Reputation: 110980

User Input + Ruby + Regex?

I want to give users a text area where they can enter text. Later I will match that input against a different input and extract it if matched.

Flow:

Then I use the following to extract:

text_reply = text_reply.sub(/#{user.text_to_extract}/m, '').strip

Problem is that it appears that characters like new lines or pipes | are breaking it. As input that we want to match against can look like this:

XXXXXX

XXXXXX
XXXX & XXXXX
asdasd: 123312321 | dasasddsadasads

http://yahoo.com

Suggestions? Thansk

Upvotes: 8

Views: 2076

Answers (1)

Michael Papile
Michael Papile

Reputation: 6856

You need to escape the input: http://www.ruby-doc.org/core/classes/Regexp.html

See the method escape.

 Regexp.escape(your_input)

Upvotes: 15

Related Questions