Tapatalk

Find in the selection

Find in the selection

10
Basic UserBasic User
10

    Oct 15, 2007#1

    Hello,

    Is there a way to make the Find instruction apply only on the selected text ? For example I would like to check if the selected text match a regular expression. How can I do that with a macro?

    6,685587
    Grand MasterGrand Master
    6,685587

      Oct 15, 2007#2

      This was so often asked and the answer was always the same: NO (for UE < 14.00).

      I have written about a workaround by using Replace All SelectText "..." in macros which can be in some situations used as I have done it several times in my macros - see my sticky forum topic in the macro forum and the documentations in the ZIP archive you can download there.

      A workaround is always to copy or cut the selection to a new file and run the finds there.

      With the script engine it is now also possible to load a selection into a string variable and run a replace on this variable. I don't know if it is also possible to run a find only on a string variable. Never needed this and so never tried it.

      Edit on 2009-10-09: With UltraEdit v14.00 and UEStudio v6.50 and later it is possible to search only in the current selection. But when a string is found in the selection, the selection is discarded and a new selection is made containing only the found string.
      Best regards from an UC/UE/UES for Windows user from Austria

      262
      MasterMaster
      262

        Oct 15, 2007#3

        Just to answer Mofis question regarding scripts and finds on string variables:

        You could for example do something like this: The script checks if a simple SQL date pattern can be found anywhere in a selection and shows a message box with the result:

        Code: Select all

        var selectedText = UltraEdit.activeDocument.selection; /* get selected text */
        
        if(selectedText.length>0) { /* anything selected ? */
        	
        	/* let's search for a simple SQL date patttern */
        	var findResult = selectedText.match(/\d\d-\d\d-\d\d\d\d/); /* javascript use it's own Perl regexp engine */
        
        	if(findResult==null) { /* nothing found returns a null object */
        		UltraEdit.messageBox("Date pattern not found");
        	}
        	else {
        		UltraEdit.messageBox("Date pattern found: "+findResult);
        	}
        }
        To mathmax: The above will only work if you are using UE version 13 and above.

        10
        Basic UserBasic User
        10

          Oct 16, 2007#4

          The problem is that scripts cannot be executed with shortcuts...

          262
          MasterMaster
          262

            Oct 16, 2007#5

            Sure they can if you by shortcuts mean hotkeys. I use it all the time. Access Scripting - Scripts... menu and notice the Hotkey and chord columns. Just click in the hotkey column beside the script you want to assign a hotkey. Then press the key combination you want.