admin管理员组文章数量:1415491
I am just trying to remove bullets from the text. For example when i am copying bulleted text list from MS Word to any textbox it is showing along with bullet. Can somebody tell me how to remove any type of bullet and replaces it with "".
I have found this code from different sources, But they are not working for me.
var x=" 1. 15-20 years ";
x.replace('•\t.+', '');
alert(x); // i want out put as 15-20 years
Thank you. :-)
I am just trying to remove bullets from the text. For example when i am copying bulleted text list from MS Word to any textbox it is showing along with bullet. Can somebody tell me how to remove any type of bullet and replaces it with "".
I have found this code from different sources, But they are not working for me.
var x=" 1. 15-20 years ";
x.replace('•\t.+', '');
alert(x); // i want out put as 15-20 years
Thank you. :-)
Share Improve this question asked Jun 24, 2011 at 14:21 ReddyReddy 1,3853 gold badges23 silver badges45 bronze badges 2- And what is the actual output? Your x does not even contain a bullet. – Leif Commented Jun 24, 2011 at 14:25
- 1 you want to remove just the "•" character? or the "1." stuff – Pablo Fernandez Commented Jun 24, 2011 at 14:25
5 Answers
Reset to default 2Try this statement instead...
x.replace(/[•\t.+]/g, '');
I think this fits your needs. http://jsfiddle/ksSG8/
var x=" 1. 15-20 years ";
x = x.replace(/\s\d\.\s*/, '');
alert(x);
One part that is missing from many answers and your code is:
x = x.replace(...);
x never receives the value returned from the replace() function if you do not assign it back to x.
Do you see any • in x? No, so you can't replace it. To achieve what you want, use:
x.replace(/^\s*[0-9]+\.\s*/, '');
What the regex does is basically removing any [number].
, along with any whitespace before and after it, so what is left is the text you need.
x= x.replace(/^\s*\d+\.\s*/, ''); // strings are immutable
This solution finds both bulleted and numbered items at the beginning of the line of text, then removes them.
var x=" 1. 15-20 years ";
x.replace(/^\s*(?:[••••]|\d+)\.\t/, '');
alert(x); // i want out put as 15-20 years
I think you are trying to replace a substring, instead of replacing with a regular expression.
本文标签: regexHow to remove Bullets from the text using javascript regular expressionStack Overflow
版权声明:本文标题:regex - How to remove Bullets from the text using javascript regular expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745177560a2646314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论