Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: regular expression to insert spaces into string of characters


Message #1 by "Bruce Reid" <hbreid@a...> on Wed, 9 May 2001 01:55:20
> I wish to convert a string of characters (for example, 
> actgcattacgcattacggcccccccc)of indefinite length provided by user input 
> into groups of three characters separated by spaces (for example, act 
gca 
> tta cgc att acg gcc ccc ccc). 
> 
> Can you suggest procedure to use regular expressions to search and 
replace 
> ?
> 


Give this a try:
   var s = new String("actgcattacgcattacggcccccccc...");
   s = s.replace(/([a-z]{3})/, "$1 ");

  Return to Index