基于重复的字符串拆分 [英] String split based on repetitions
本文介绍了基于重复的字符串拆分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个字符串值(11112233
)。我想拆分这个字符串并将其分成3个不同的值。
I have a string value ("11112233"
). I want to split this string and separate it to 3 different value.
Val 1 = 1111
val 2 = 22
val 3 = 33
我搜索了很多,其中包括( /
)或其他符号。
别的,我的号码总是不同的,所以我不能通过输入确切的字符串来拆分它。
我想做这样的事情:
I searched a lot, its possible with characters like (/
) or other symbols.
Something else, My number is always different, so i cant split it by enter the exact string.
I want to do something like this:
var myVal = "11112233";
var lastVal = myVal.split(0 , 3); // split from index 0 till index 3
我怎么做?
谢谢
How i can do it?
Thanks
推荐答案
试试这个正则表达式:
'121112233'.match(/(\d)\1*/g) // ["1", "2", "111", "22", "33"]
\ * *
表示与之前相同匹配,零次或多次。
\1*
means "same as previous match, zero or more times".
这篇关于基于重复的字符串拆分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文