Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4722

    bora
    Member

    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.

    #4723

    CaptainFlint
    Participant

    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);

    #4724

    bora
    Member

    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!)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Share with friends... Tweet about this on TwitterShare on FacebookShare on Google+Email this to someone