EmEditor (text editor) Forum Index
   Questions and Answers about EmEditor Core
     extract text
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
user
Posted on: 5/2/2012 1:04 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
extract text
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!
Stefan
Posted on: 5/2/2012 2:36 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Re: extract text
Delete 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 Function
user
Posted on: 5/2/2012 3:33 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: extract text
thanks but how do I use this?

I save it as .vbs file and load it as macro

what's next?

thanks
Stefan
Posted on: 5/2/2012 10:36 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Macro Delete Lines NOT containing STRING RegEx Pattern
user> 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

Stefan
Posted on: 5/2/2012 11:10 am
Home away from home
Joined: 7/14/2008
From: Germany, EU
Posts: 285
Delete Lines NOT containing STRING RegEx Pattern Bookmark


Note, 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"

user
Posted on: 5/3/2012 7:07 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: Macro Delete Lines NOT containing STRING RegEx Pattern
ok 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 :/
user
Posted on: 6/4/2012 1:37 am
Home away from home
Joined: 9/29/2006
From:
Posts: 212
Re: Macro Delete Lines NOT containing STRING RegEx Pattern
it says that there is an error at line 17, any hint???
Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文