Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有地址的字符串:
3rd Street Promenade, Santa Monica, CA, United States
我如何在第二个逗号之后(包括)非破坏性地把它切掉?
这将在视图中使用,以便尽可能简洁。
"3rd Street Promenade, Santa Monica, CA, United States"[/[^,]*,?[^,]*/] # => "3rd Street Promenade, Santa Monica"
'3rd Street Promenade, Santa Monica, CA, United States'.clone.split(/,/).take(3).join(', ')