Match all occurance of double quotes in a string

I have a string something like this...
"Now is the time for all good men to blah, blah..." - Origin unknown

I want to convert it to this...
[i]Now is the time for all good men to blah, blah...[/i] - Origin
unknown

With the first double quote converted to "[i]" and the second to "[/i]".
The occurance of the 1st double quote may or may not be at the beginning
of the string.

···

--
Posted via http://www.ruby-forum.com/.

Patrick Spence wrote:

I have a string something like this...
"Now is the time for all good men to blah, blah..." - Origin unknown

I want to convert it to this...
[i]Now is the time for all good men to blah, blah...[/i] - Origin unknown

With the first double quote converted to "[i]" and the second to "[/i]". The occurance of the 1st double quote may or may not be at the beginning of the string.

Rather simplistic, but should work:

string.sub(/"([^"]*)"/, '[i]\1[/i]')

···

--
Alex

Alex Young wrote:

Patrick Spence wrote:

Rather simplistic, but should work:

string.sub(/"([^"]*)"/, '[i]\1[/i]')

I like simple, thanks!

···

--
Posted via http://www.ruby-forum.com/\.