- AuthorPosts
- May 2, 2012 at 9:04 am #10301userParticipant
hello!
my goal is to extract specific text from a text file
I search for a specific regex, I want to select all the matches of this regex, then I want to reverse selection and delete that selection, so that only the regex matches will be left
can you tell me please how to do this (particularly the “select all” and “reverse selection” parts) or a better way to do it
thanks!
May 2, 2012 at 10:36 am #10302StefanParticipantDelete Lines NOT containing STRING
#language = "VBScript"
FileText = document.selection.Text
If FileText = "" Then
alert "Nothing selected?" & vbCRLF _
& "This script works with selected text only."
Quit
End If
PromptText = "Remove lines containing this search string"
searchStr = prompt(PromptText, "")
If searchStr = "" Then Quit
Lines = Split(fileText, vbCRLF)
For each line in Lines
funcRegEx searchStr, line
'//FALSE = line not contains search pattern
'//TRUE = line contains the search pattern
If funcRegExReturn = FALSE Then
resultText = resultText + line + vbCRLF
End If
Next
'editor.NewFile()
document.writeln(resultText)
Function funcRegEx(needle, haystack)
funcRegExReturn = FALSE
Set regEx = New RegExp
regEx.Pattern = needle
regEx.IgnoreCase = True
regEx.Global = True
If regEx.Test(haystack) Then
funcRegExReturn = TRUE
End If
End FunctionMay 2, 2012 at 11:33 am #10303userParticipantthanks but how do I use this?
I save it as .vbs file and load it as macro
what’s next?
thanks
May 2, 2012 at 6:36 pm #10305StefanParticipantuser> what’s next?
??
* Save this script/macro to an text file with VBS or VBEE extension.
(please save it again, i have edited an comment failure in the meantime)* Macros > Select this (means the current open macro file)
or use
* Macros > Select… >>> choose the macro* Open your text file to edit.
* Select an paragraph or the whole text (Ctrl+a)* Execute the macro: Macros > Run myMacro.vbs
??
EmEditor Help > EmEditor Macro Reference > Tutorial > Run Macro
May 2, 2012 at 7:10 pm #10306StefanParticipantNote, with last beta
“Head-start version: EmEditor Professional v11.1.6 beta”you can also use:
* Find: [ pattern ] with [Bookmark all]
* “Invert Bookmarks in This Group”
* “Delete Bookmarked Lines in This Group”May 3, 2012 at 3:07 pm #10309userParticipantok but where do I specify the regex???
> Delete Bookmarked Lines in This Group”
I dont want to delete the bookmarked lines, I want to delete the inverted selection :/June 4, 2012 at 9:37 am #10393userParticipantit says that there is an error at line 17, any hint???
- AuthorPosts
- You must be logged in to reply to this topic.