ES5.6 does not provide an API directly for custom segmentation, but you can use regular expressions to implement the desired segmentation logic.
Here is sample code that uses regular expressions:
var str = "c3d4"; var regex = /(\w+\d+)|(\w+)/g; // 按照下划线分词并每个小的整体细分 var tokens = str.match(regex); // 获得分词后的数组 console.log(tokens); // ["a1b2", "a1", "b2", "c3d4", "c3", "d4"]
in the sample code above, we use regular expressions/(\ w + \ d +) |(\ w +)/g string according to the underlined word segmentation and every small segment. In the regular expression, \ w match any letters, Numbers, and underscores, \ d match any number, + means to match one or more, or |, grouping(), g said global matching.
We use the str.match(regex) method to get a segmented array, where each element is a segmented array. For example, the first participle is "a1b2", the second participle is "a1", the third participle is "b2", and so on.
Using this method, you can define the segmentation logic according to your needs to achieve more detailed segmentation.