Tapatalk

How to replace straight quotation marks by the double low and double right quotation marks?

How to replace straight quotation marks by the double low and double right quotation marks?

232
Basic UserBasic User
232

    Apr 10, 2023#1

    Hello,

    I need your help. First of all, I have hardly any idea about regular expression and JavaScript 😢

    The following issue: I have several extensive documents (txt files) containing quotation marks in the following format:

    "Test" ... more text ... "Test"

    How can I now replace the first " with „ throughout the text to get „Test"?

    Any ideas?

    Greetings Frank.
    (Translated with DeepL)
    Win11 (64bit) 23H2 - UE 2024.0.0.35 64bit

    6,685587
    Grand MasterGrand Master
    6,685587

      Apr 10, 2023#2

      Make a backup of all *.txt files in the folder and then run a regular expression Repace in Files with
      • UltraEdit regular expression searching for ["„]^([~"“”]++^)["“”] and replacing all found occurrences with „^1” as described by the power tip tagged regular expression
        or
      • Unix or Perl regular expression searching for ["„]([^"“”]*)["“”] and replacing all found occurrences with „\1” as described by the power tip Perl regular expression using backreferences.
      Please be aware of the fact that a regular expression does not understand the text and the meaning of a double quote in context of the text. If a text file contains anywhere for example 15" screen or 15° 20' 45". A regular expression does not know that first " means inch in this context and second " means arcsecond in this context. A regular expression also does not know which part of a text is a code block of a programming or scripting language on where only " is valid.

      I recommend to run after the Replace in Files a Find in Files with UltraEdit search regular expression ["„][~"“”]++["“”] or with Unix/Perl search regular expression ["„][^"“”]*["“”] and inspect each found occurrence if the quotes are really correct in context.
      Best regards from an UC/UE/UES for Windows user from Austria

      232
      Basic UserBasic User
      232

        Apr 12, 2023#3

        Hi Mofi,

        thank you, it works perfectly manually. Exactly what I was looking for. 👍

        But if I try that in my function, nothing happens.
        Script does not show any error message, but nothing is replaced.
        I think the expression still has to be adjusted?
        But how?
        please, please ... 🙏

        Here is my function:

        Code: Select all

        var _ue         = UltraEdit;
        var _regExp;
        var _replace    = '';
        
        var _thisDoc    = _ue.activeDocument;
        _ue.ueReOn;
        // _regExp   = ["„]^([~"“”]++^)["“”]; (Error)
        // _regExp   = "["„]^([~"“”]++^)["“”]"; (Error)
        // _regExp   = '["„]^([~"“”]++^)["“”]'; (no Error, no founds)
        _replace  = '„^1”';
        fn_ReplaceDoc();
        
        
        //  ------------------------------------------------------------------------  //
        function fn_ReplaceDoc()
          {
            _thisDoc.top();
            _thisDoc.findReplace.regExp = true;
            _thisDoc.findReplace.replaceAll=true;
            _thisDoc.findReplace.replace(_regExp,_replace);
          }
        
        
        greetings Frank
        (Translated with DeepL)
        Win11 (64bit) 23H2 - UE 2024.0.0.35 64bit

        6,685587
        Grand MasterGrand Master
        6,685587

          Apr 13, 2023#4

          The script code below works which defines all parameters for the UltraEdit regular expression replace all in active file.

          Code: Select all

          var _ue      = UltraEdit;
          var _regExp;
          var _replace = '';
          
          var _thisDoc = _ue.activeDocument;
          _ue.ueReOn();
          _regExp   = '["„]^([~"“”]++^)["“”]';
          _replace  = '„^1”';
          fn_ReplaceDoc();
          
          //  ------------------------------------------------------------------------  //
          
          function fn_ReplaceDoc()
          {
             _thisDoc.top();
             _thisDoc.findReplace.mode=0;
             _thisDoc.findReplace.matchCase=true;
             _thisDoc.findReplace.matchWord=false;
             _thisDoc.findReplace.regExp=true;
             _thisDoc.findReplace.searchDown=true;
             if (typeof(_thisDoc.findReplace.searchInColumn) == "boolean")
             {
                _thisDoc.findReplace.searchInColumn=true;
             }
             _thisDoc.findReplace.preserveCase=false;
             _thisDoc.findReplace.replaceAll=true;
             _thisDoc.findReplace.replaceInAllOpen=false;
             _thisDoc.findReplace.replace(_regExp,_replace);
             _thisDoc.top();
          }
          
          Your mistake was _ue.ueReOn; instead of _ue.ueReOn(); in the fifth line.

          The statement without the round brackets just tests if there is a symbol (variable, function) with that name defined without evaluation of the result. That has no effect on running the script.

          The command with the round bracket results in a real function call as it is necessary to change the regular expression engine from the built-in default Perl to UltraEdit.

          The UltraEdit regular expression engine finds the strings to replace with the correct search string definition. The Perl regular expression engine does not find any string matching the expression being interpreted different by the Perl regular expression engine.
          Best regards from an UC/UE/UES for Windows user from Austria

          232
          Basic UserBasic User
          232

            Apr 13, 2023#5

            Hi Mofi

            Your mistake was _ue.ueReOn; instead of _ue.ueReOn(); in the fifth line.
            In fact, I already had that with another function. It is difficult to see if no error is displayed.

            But now it works perfectly.
            Thanks for the expansion of my function.

            I am usually more working with VBA and JavaScript and regular expressions are a great change for me as a layperson.

            By the way: Is there actually a list of supporting JavaScript commands and functions ??

            Unfortunately, I have to find out again and again that a lot is not supported in UE. (started at Let)


            greetings Frank

            IMTranslator is s....t 😠
            (Translated with DeepL)
            Win11 (64bit) 23H2 - UE 2024.0.0.35 64bit

            6,685587
            Grand MasterGrand Master
            6,685587

              Apr 13, 2023#6

              Open the help of UltraEdit for Windows, select tab Index, type in edit field scripting and double click on list item Scripting commands to get displayed the help page with all UltraEdit specific functions and properties.

              There is also the tag list UE/UES Script Commands. Click on ribbon tab Layout on check box item Tags and select in the list UE/UES Script Commands. The Tag List can be opened also by clicking in contemporary menu Layout on menu item Tags or in traditional menu View in submenu Views/lists in submenu Lists on menu item Tag list. Double click on an item to insert a tag, around the current selection if the tag is written to insert the tag around a selected text like a variable name.

              There is embedded in UltraEdit up to v2022.2.0.52 the Mozilla JavaScript core engine version 1.8.1 (version 3.1 of ECMAScript) which is pretty old, but usually enough for UltraEdit script writers. For more information see Why does a call of string function match with a regular expression with a look-behind result in an assertion? The core functions and properties can be found in the Mozilla JavaScript documentation under list item Standard built-in objects.

              UltraEdit for Windows v2023.0 offers the usage of Microsoft WebEngine2 for the script execution on being available on used version of Windows. In other words UE v2023.0 supports for UltraEdit scripts everything supported by latest version of JavaScript core engine as in currently installed WebEngine2.
              Best regards from an UC/UE/UES for Windows user from Austria