EmEditor (text editor) Forum Index
   Regular Expressions
     Changing multiple spaces to one space
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
bora
Posted on: 10/5/2007 2:22 am
Just popping in
Joined: 10/5/2007
From:
Posts: 5
Changing multiple spaces to one space
Hello everybody!

Have this problem: want to write a macros with regular expression to change all multiple spaces in a document to single spaces.

I use this line:
document.selection.Replace('(\s){2,}', '\1', eeFindReplaceRegExp | eeReplaceAll);

But when I ran this macros in the editor it says (in status bar) that it Cannot find (s){2,} anywhere in document. Note the absence of the backslash before "s" in this status message.

(I also tried to escape the backslash like this (\\s){2,}, then the "finding" part works, but it replaces it not with a regular space but with a character with code 01H)

Does anyone has any ideas about this problem? I would appreciate any help.
Flint
Posted on: 10/5/2007 2:44 am
Home away from home
Joined: 10/9/2006
From: Moscow
Posts: 155
Re: Changing multiple spaces to one space
JavaScript has its own Escape-character '\' and uses it for its own purposes. So, when you write '\s' JavaScript converts it into single 's', when you write '\1' it is converted into character with octal code 001, etc. The correct expression hence would be:
document.selection.Replace('(\\s){2,}', '\\1', eeFindReplaceRegExp | eeReplaceAll);
bora
Posted on: 10/5/2007 5:56 am
Just popping in
Joined: 10/5/2007
From:
Posts: 5
Re: Changing multiple spaces to one space
Thank you very much, Flint! You helped me out here!
(I'm a beginner in javascript. Started to learn it a couple of days ago after encountering that powerful macro engine in EmEditor. Great tool indeed!)
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文