0
那么,如何做,在常规(或Java)?我期待这样的事情:如何替换字符串中匹配N个?
someString.replaceN(/(?<=\p{L}) (?=\p{L})/, '', 3) // replace first 3 matches
现在,我只是来这个愚蠢的解决方案:
(0..2).each { s = s.replaceFirst(/(?<=\p{L}) (?=\p{L})/, '') }
在其他语言中是易如反掌:
- 的Python - subn(count=3)
- PHP - preg_replace(limit=3)
- 拉斯特 - Regex.replacen