ohho
ohho

Reputation: 51921

How to write a ruby regex that removes characters only at first and last positions?

I have a log file, most lines are quoted at first and last character, like:

 "2010-09-09,13:33,"user logoff",0"

What's the ruby regex to remove the head and tail quotation marks? so the result string looks like:

 2010-09-09,13:33,"user logoff",0

Upvotes: 3

Views: 3861

Answers (2)

Chubas
Chubas

Reputation: 18043

Or without regular expressions:

string[1...-1]

Upvotes: 3

Alex Wayne
Alex Wayne

Reputation: 187004

str.gsub /^"|"$/, ''

Upvotes: 8

Related Questions