string =

"
[title]

{snippet}

[something else in bracket]

{something else}

more text

#tags
"

我要删除第一个出现的[]和{}
s.clean_方法或regexp应该返回这样的字符串
"
title

snippet

[something else in bracket]

{something else}

more text

#tags
"

语言Ruby 1.9.2

最佳答案

更多相同的:

s = "[asd]{asd}[asd]{asd}"
%w({ } [ ]).each{|char| s.sub!(char,'')}
#=> "asdasd[asd]{asd}"

关于ruby - 从字符串中删除首次出现的给定字符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4275862/

10-11 13:44