Menu

UPPERCASE tag area in regex search+replace

2008-02-22
2012-11-13
  • Nobody/Anonymous

    I would like to replace a tagged area with UPPERCASE converted characters (regular expression search and replace).
    Some help would be appreciated as I've been trying to figure that out for quite some time now.

    Thanks!

     
    • pshute

      pshute - 2008-02-29

      The TextFX Character plugin can convert selected text to uppercase, lowercase, etc.

       
    • Nobody/Anonymous

      Perhaps using a macro will be the way to go here. You have to pre-set the Find dialog and then use F3 and CTRL+SHIFT+U in the macro and run it until the end of the file.

       
      • Nobody/Anonymous

        That sounded like a good idea but for some reason the uppercase conversion deletes the selected text when run from a macro.
        It works fine when I just repeatedly press [F3 -> Ctrl+Shift+U] but that's hardly practical as I'm working with some huge text files here.

         
        • Nobody/Anonymous

          Perhaps you could create an AutoHotKey script/macro as an alternative then.

           
          • kolya

            kolya - 2008-02-26

            In the end a friend wrote a javascript for me to do the replacements.

            Still it would be nice if NP++ would support these operators:

            \u = next letter upperase
            \U = following letters uppercase
            \l = next letter lowercase
            \L = following letters lowercase
            \E = stop case conversion at this point

             
            • Nobody/Anonymous

              It's always good to have a friend do your work.

               
              • kolya

                kolya - 2008-02-27

                I'll answer this with what he said: "Thanks for the fun problem."
                Yeah, I guess it's good to have friends like that. Here's the script:

                // Save this as "replace.js".
                // File to be converted is called "file.txt".
                // Delimiters of the text to be converted are "<pattern>" and "</pattern>" here.
                // To start the script enter on a command prompt:
                // cscript //E:jscript //NoLogo replace.js > new.txt
                // "new.text" contains the converted data
                var fso = new ActiveXObject('Scripting.FileSystemObject');
                var fs = fso.OpenTextFile('file.txt');
                var s = new String(fs.ReadAll());
                fs.Close();
                s = s.replace(/<pattern>(.*?)<\/pattern>/gi, function($1){ return $1.replace(/>.*</, function($1){ return $1.toUpperCase();})});
                WScript.Echo(s);

                 
    • Nobody/Anonymous

      > I would like to replace a tagged area with UPPERCASE converted characters (regular expression search and replace).

      It would be a great thing if regex did that (among others).  Too bad it doesn't come that way.  I wonder how hard it would be to modify regex ....... hmmmmmmmm

       
MongoDB Logo MongoDB