我正在尝试编写一个正则表达式,实现以下功能:
General Motors --> General Motors (stays the same!)
Yahoo! --> Yahoo (remove exclamation point)
Le7el --> Le7el
Mat. Science --> Mat Science我尝试了一个简单的"/\W+$/",但不幸的是,它只捕捉到行尾的标点符号。
发布于 2013-11-07 18:51:52
['General Motors','Yahoo!','Le7el','Mat. Science'].map{|e| e.tr('.!','')}
# => ["General Motors", "Yahoo", "Le7el", "Mat Science"]
['General Motors','Yahoo!','Le7el','Mat. Science'].map{|e| e.gsub(/[[:punct:]]/,'')}
# => ["General Motors", "Yahoo", "Le7el", "Mat Science"]https://stackoverflow.com/questions/19844190
复制相似问题