1
3
您可以在
|
2
2
使用regex来实现这一点。 例如,您可以检查一个或多个制表符、空格或换行符的匹配数,并使用它们的计数。
正则表达式规则是:
对于JavaScript:
Regex是一种非常有效的方法。或者,您必须通过对象手动迭代,并尝试匹配存在一个或多个空格、制表符或换行符的情况。 考虑一下,您试图做的是在编译器中使用,以便将特定字符序列识别为特定元素,称为标记。这种做法被称为 词法分析 ,或标记化。由于regex存在,因此无需手动执行此检查,除非您想执行一些非常高级或特定的操作。 |
3
1
这是一个丑陋的解决方案,没有使用任何正则表达式,从性能上看,它是最优的,但它可以变得更具python风格。
|
4
1
Stéphane Ammar's solution 这可能是最简单的,但如果你想要更高性能的东西:
|
Softly · 单选按钮未按预期取值 1 年前 |
SlickRed · 我无法使用JS关注HTML元素 1 年前 |
assembler · Nextjs没有处理发布请求 1 年前 |
BADRUM · 执行两个获取功能后,如何导航回页面? 1 年前 |
Toniq · javascript为php保存多维数组 1 年前 |