RegExp split a string by its middle character matches

╄→尐↘猪︶ㄣ 提交于 2020-03-05 01:30:46

问题


I'd like to split all the instances of a character that aren't the starting or ending character. For example: "go good golly gog".split(RegExp) would go to ["go ","ood ","olly ","og"].

Is this RegExp possible?


回答1:


Is this what you want?

"go good golly gog".split(/(?!^)g(?!$)/)


来源:https://stackoverflow.com/questions/6448461/regexp-split-a-string-by-its-middle-character-matches

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!