ruby parametrized regular expression

Posted by astropanic on Stack Overflow See other posts from Stack Overflow or by astropanic
Published on 2010-05-07T14:35:06Z Indexed on 2010/05/07 14:38 UTC
Read the original article Hit count: 206

Filed under:
|
|

I have a string like "{some|words|are|here}" or "{another|set|of|words}"

So in general the string consists of an opening curly bracket,words delimited by a pipe and a closing curly bracket.

What is the most efficient way to get the selected word of that string ?

I would like do something like this:

@my_string = "{this|is|a|test|case}"
@my_string.get_column(0) # => "this"
@my_string.get_column(2) # => "is"
@my_string.get_column(4) # => "case"

What should the method get_column contain ?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about string