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.

Community
  • 1
  • 1
BSG
  • 1,382
  • 4
  • 14
  • 25

2 Answers2

5

What's wrong with using String#split?

longString.split('-')
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
4

Why not just use string.split()?

longString.split('-');
J. Holmes
  • 18,466
  • 5
  • 47
  • 52