When I do "www.example.com/test/test".gsub('/test','')
, I get "www.example.com"
, but my desired result is "www.example.com/test"
. That is, only the last "/test"
should be removed. How do we achieve it?
Use "www.example.com/test/test".gsub(/\\/test$/,'')
UPDATE after comment
Event if it is working with gsub
, sub
seems more appropriate as you only want to replace one time :
"www.example.com/test/test".sub(/\\/test$/,'')
尝试这个
"www.example.com/test/test".sub('/test','')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.