admin管理员组

文章数量:1289891

I am copyig some data from the MS Word. That text may contain or May not contain Bullets in the copied text. But i need a Regular expression in javascript to remove any type of Bullets from the copied text.
for example if i copy the text which is having bullets it is ing like this when i paste it.
Here are some examples

 1.   Jnflkvkbfjvb
 2.   Kjnfbhvjbv
 3.   ;kbvrjvbrjvb 

 •    Jnflkvkbfjvb  
 •    Kjnfbhvjbv  
 •    ;kbvrjvbrjvb  

 a)   Jnflkvkbfjvb
 b)   Kjnfbhvjbv
 c)   ;kbvrjvbrjvb 

 A.   Jnflkvkbfjvb
 B.   Kjnfbhvjbv
 C.   ;kbvrjvbrjvb 

  I.      Jnflkvkbfjvb
 II.      Kjnfbhvjbv
III.      ;kbvrjvbrjvb 

But My requirement is to display without any of these bullets.It has to display

       Jnflkvkbfjvb
       Kjnfbhvjbv
       ;kbvrjvbrjvb

My code is

      var  x=" •    Jnflkvkbfjvb•    Kjnfbhvjbv•    ;kbvrjvbrjvb 1.     Jnflkvkbfjvb2.    Kjnfbhvjbv3.    ;kbvrjvbrjvb ";
      x= x.replace(/[•\t.+]/g, ''); 
      x= x.replace(/[[1-9][.]\t.+]/g, '');
      alert(x);

Please someone help me.
You can use this to edit the code
/

I am copyig some data from the MS Word. That text may contain or May not contain Bullets in the copied text. But i need a Regular expression in javascript to remove any type of Bullets from the copied text.
for example if i copy the text which is having bullets it is ing like this when i paste it.
Here are some examples

 1.   Jnflkvkbfjvb
 2.   Kjnfbhvjbv
 3.   ;kbvrjvbrjvb 

 •    Jnflkvkbfjvb  
 •    Kjnfbhvjbv  
 •    ;kbvrjvbrjvb  

 a)   Jnflkvkbfjvb
 b)   Kjnfbhvjbv
 c)   ;kbvrjvbrjvb 

 A.   Jnflkvkbfjvb
 B.   Kjnfbhvjbv
 C.   ;kbvrjvbrjvb 

  I.      Jnflkvkbfjvb
 II.      Kjnfbhvjbv
III.      ;kbvrjvbrjvb 

But My requirement is to display without any of these bullets.It has to display

       Jnflkvkbfjvb
       Kjnfbhvjbv
       ;kbvrjvbrjvb

My code is

      var  x=" •    Jnflkvkbfjvb•    Kjnfbhvjbv•    ;kbvrjvbrjvb 1.     Jnflkvkbfjvb2.    Kjnfbhvjbv3.    ;kbvrjvbrjvb ";
      x= x.replace(/[•\t.+]/g, ''); 
      x= x.replace(/[[1-9][.]\t.+]/g, '');
      alert(x);

Please someone help me.
You can use this to edit the code
http://jsfiddle/V2aSg/

Share Improve this question edited Jun 25, 2011 at 16:55 Reddy asked Jun 25, 2011 at 16:32 ReddyReddy 1,3853 gold badges23 silver badges45 bronze badges 4
  • I Have been trying it.. But as of now it is removing only round bullets. – Reddy Commented Jun 25, 2011 at 16:32
  • 1 what code have you tried? Could you add it as well? – Dogbert Commented Jun 25, 2011 at 16:33
  • Is this you want. – Asad Rasheed Commented Jun 25, 2011 at 16:53
  • @Asad Rasheed yes, But please modify your code to make it also work by identifying automatically.Any type of bullet... – Reddy Commented Jun 25, 2011 at 17:03
Add a ment  | 

2 Answers 2

Reset to default 10

Try this

/^\s*(?:[\dA-Z]+\.|[a-z]\)|•)\s+/gm

See it here at Regexr

This checks

^ The start of the row (with the modifier m)

\s* any amount of whitespace

[\dA-Z]+\. At least one (+) digit or A-Z followed by a dot

or

[a-z]\) a-z followed by a )

or

\s+ At least one whitespace at last

If we need it for multiple auto-numbered list like

  1. Content

    1.1. Content and so on 1.1.1...

Then this regex would (.*?)\d\.\s+|[a-z]\)\s+|•\s+|o\s+|[A-Z]\.\s+|[IVX]+\.\s+|[ivx]+\.\s+

Also, in my case i did not need the empty lines to be replaced/highlighted

Regex Demo

本文标签: javascriptHow to identify and Remove any type of Bullet in the TextStack Overflow