Advertisement
rplantiko

UltraEdit - grep

Jul 8th, 2012
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Behält nur die Zeilen, die den Filter-RegExp erfüllen (oder nicht erfüllen)
  2. res = UltraEdit.getString("Filter (RegExp). Negativ: 'v ' voranstellen",1);
  3. var positive = true;
  4. if (res.match(/v\s+(.*)/)) {
  5.   positive = false;
  6.   res = RegExp.$1;
  7.   }
  8. var re = new RegExp( res );
  9.  
  10. var doc = UltraEdit.activeDocument;
  11. if (!doc.selection.match(/\S/)) doc.selectAll();
  12. var selection = doc.selection
  13.                    .replace( /^\xEF\xBB\xBF/,"")  // Unicode-BOM
  14.                    .replace( /\x00/g,"");         // Unicode-Bytes enfernen
  15.  
  16. var lineEnd   = selection.match( /[\r\n]{1,2}/ ) || "\r\n" ;
  17. var lines     = selection.split( lineEnd );
  18. var result    = "";
  19. var lineMatches;
  20.  
  21. for (var i=0;i<lines.length;i++) {
  22.   lineMatches = !! lines[i].match(re);
  23.   if (positive == lineMatches) result += lines[i] + lineEnd;
  24.   }
  25.  
  26. doc.write( result );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement