ES5.6 How Do I Divide Words by Underscores Before Subdividing them?

deny0508 注册会员
2023-02-27 14:08

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.

duxinjian44 注册会员
2023-02-27 14:08

"settings": {
"analysis": {
"char_filter": {
"XtoS": {
"type": "mapping",
"mappings": ["_=>|"]
"analyzer": {
"my_analyzer": {
"type": "custom",
"char_filter": ["XtoS"],
"tokenizer": "standard",
"filter": ["lowercase"]
I did this but now I can only do this by underlining; May I ask how to rectify this kind of reform? Because I need to sort out the segmentation logic and put ES