Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #26140
    David
    Participant

    In EmEditor help system, there are some Javascript samples of \J in Replacement of Regular Expression.
    http://www.emeditor.org/en/howto_search_replacement_expression_syntax.html

    Replacement Expression		Meaning
    \J "\0" + "abc"			joins the matched string and "abc"
    \J substr( "\0", 0, 5 )		returns the first 5 characters of the matched string

    I try the first replacement expression \J “\0” + “abc” , it works very well. But when I try the second one,there’s an error dialog “macro error: ‘substr’ is not defined”. What’s reason for this error?

    Another question, besides ‘substr()’,if possible to use other JS Functions, such as getDate(),getYear(),…….Thanks!

    #26141
    Yutaka Emura
    Keymaster

    It should be written as:

    \J "\0".substr( 0, 5 )

    We will fix the Help.

    You can use any JavaScript script here. For instance:

    \J var d = new Date(); d.getFullYear() + "-" + ( d.getMonth()+1 ).toString() + "-" + d.getDate();

    Thank you,

    #26142
    David
    Participant

    Hello,Yutaka Sung, Thanks for your quick reply.
    I made an incorrect description. My second question is: in the Replacement Expression
    \J "\0".substr( 0, 5 )
    Besides .substr() in the \J expression, if possible to use other Functions.For example:

    \J "\0".Left( 0, 5 )
    \J "\0".Right( 0, 5 )
    \J "\0".Upper( ).......

    In the help system, only .substr is mentioned.

    #26146
    Yutaka Emura
    Keymaster

    Hello David,

    You can use any JavaScript String methods. “\0” is considered a String. Left and Right are not JavaScript, but you can use any other JavaScript methods here. Please refer to JavaScript string methods:

    https://www.w3schools.com/jsref/jsref_obj_string.asp

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.