Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10301
    user
    Participant

    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!

    #10302
    Stefan
    Participant

    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
    #10303
    user
    Participant

    thanks but how do I use this?

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

    what’s next?

    thanks

    #10305
    Stefan
    Participant

    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

    #10306
    Stefan
    Participant

    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”

    #10309
    user
    Participant

    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 :/

    #10393
    user
    Participant

    it says that there is an error at line 17, any hint???

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.