【发布时间】:2022-01-22 18:03:10
【问题描述】:
如何从字符串中提取符号、数字、最多 3 个单词和至少 4 个字母的单词,并将它们分别存储到相应分类的数组中?
给定的字符串是:
const string = 'There are usually 100 to 200 words + in a paragraph';
预期的响应是:
const numbers = ['200', '100'];
const wordsMoreThanThreeLetters = ['There', 'words ', 'paragraph', 'usually'];
const symbols = ['+'];
const words = ['are', 'to', 'in', 'a'];
【问题讨论】:
-
你能提供预期的输出和你的任何尝试吗 -> How to Ask -> Minimal, Reproducible Example
-
如果将不带任何标签的字符串放入数组中,则无法区分不同长度的字符串。所以在标记化过程中区分它们是没有用的。
标签: javascript regex string reduce tokenize