如何使用 jQuery 按位置删除字符串的一部分
我需要通过插入符号位置删除文本区域值的一部分...这个值可以是这样
### something
### another
###
,所以我想删除空白元素“###”。因为删除操作是通过按下 Enter 来调用的——所以在添加“\n”之前。我不能使用
.replace('### \n')
,因为没有'\n',如果没有它,JS将删除第一行中的“###”。
我想,我必须使用正则表达式,但我找不到它:(我尝试过使用类似的东西,
$(h.textarea).val($(h.textarea).val().replace('/(\s{2,}\#{3})(\s+)/g', ''));
你能帮我找到正确的表达式吗?
I'm need to delete a part of the textarea value by caret positions... This value can be
### something
### another
###
so i want to remove the blank element "### ". because the remove action calls by the Enter pressed — so before adding "\n". and i can't use
.replace('### \n')
because there is no '\n', and without it, the JS will remove "### " in the first line.
i think, i must use regular expression, but i cannot find it :( i've tried to use something like this
$(h.textarea).val($(h.textarea).val().replace('/(\s{2,}\#{3})(\s+)/g', ''));
can you help me to find the correct expression?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
你可以在这里查看:http://jsfiddle.net/sbPGc/
Try this instead
You can check it out here: http://jsfiddle.net/sbPGc/
尝试使用 .replace('^#{3}\s*$', '') 代替。 ^ 匹配行开头,$ 匹配行结尾。
Try using .replace('^#{3}\s*$', '') instead. ^ matches line begining and $ matches line end.