开发者

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

开发者 https://www.devze.com 2023-01-15 03:15 出处:网络
I have a log file, most lines are quoted at first and last character, like: \"2010-09-09,13:33,\"user logoff\",0\"

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:

开发者_JAVA技巧
 2010-09-09,13:33,"user logoff",0


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


Or without regular expressions:

string[1...-1]
0

精彩评论

暂无评论...
验证码 换一张
取 消