gpt4 book ai didi

javascript - 字符串替换正则表达式,开头的空格

转载 作者:行者123 更新时间:2023-11-28 15:25:48 24 4
gpt4 key购买 nike

如何替换字符串开头的空格?

insertItem = insertItem.replace(/\A\s+/g, '').toLowerCase();

https://jsfiddle.net/m0yvn0w0/

http://www.w3schools.com/jsref/jsref_replace.asp

最佳答案

Javascript不支持\A,您需要使用^ anchor 。而且这里不需要 g 修饰符,因为每行都会发生一次替换。

insertItem.replace(/^\s+/m, '').toLowerCase();

关于javascript - 字符串替换正则表达式,开头的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29010802/

24 4 0
文章推荐: javascript - 如何在表单上执行 php 脚本后显示成功消息
文章推荐: css - 导致
文章推荐: css - 基础网格不适合
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com