[javascript] 유용한 함수 정리

Suyeon·2020년 12월 12일
0

Javascript

목록 보기
24/31

Split string and keep the separator

If you wrap the delimiter in parantheses it will be part of the returned array.

const str = "1、2、3";

str.split("、") // ["1", "2", "3"]
str.split(/(、)/g) // ["1", "、", "2", "、", "3"] // (*) ","을 포함해서 자르기
str.split(/(?=、)/g) // ["1", "、2", "、3"]
str.split(/(?!、)/g) // ["1、", "2、", "3"]
str.split(/(.*?、)/g) // ["", "1、", "", "2、", "3"]
profile
Hello World.

0개의 댓글