2

I have a long string, consisting of multiple sentences, of various length, divided by a "-".

I want to iterate over the string and extract everything between the -'s, preferably to an array.

From another thread I found something that gets me pretty close, but not all the way:

longString.scan( /-([^-]*)-/)

Needless to say, I am new to Ruby, and especially to RegEx.

2 Answers 2

5

What's wrong with using String#split?

longString.split('-')
Sign up to request clarification or add additional context in comments.

Comments

4

Why not just use string.split()?

longString.split('-');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.