Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9432
    raviniral
    Member

    I am not able to create macro for extracting only one tag from HTML file.

    My query is, I have HTML files and I want to extract only tags. There are many tags in the file but i want to extract only those have the text in between /en/ or /us/.

    Can anyone please help. It will help me to work faster.

    #9457
    Stefan
    Participant

    I don’t know if i do it the elegant way, but at least it works:

    Example text:








    Result:
    1:
    4:

    6:

    9:

    RegEx used to match wanted line:

    Script:


    strSelectedText = document.selection.Text
    If strSelectedText = "" Then
    alert "Nothing selected. Script quits."
    Quit
    Else
    'alert strSelectedText
    End If


    'regex search pattern:
    strREPattern = "<a href=.https.+/(en|us)/.+>"


    'how many lines?
    yPosStartSelection = document.selection.GetAnchorPointY( eePosLogical )
    yPosEndSelection = document.selection.GetBottomPointY( eePosLogical )
    LinesSelected = yPosEndSelection-yPosStartSelection


    'For Each Line In LineS Do:
    LinesArray = split(strSelectedText, vbCRLF)
    funcRegExReturn =""
    For LineNr = 0 to LinesSelected -1
    currLine = LinesArray(LineNr)
    'alert LineNr & ": " & currline & ": " & strREPattern
    funcRegEx strREPattern, currLine
    'alert funcRegExReturn
    If funcRegExReturn = TRUE Then
    OutArray = OutArray & Linenr+1 & ": " & currLine
    If LineNr < LinesSelected -1 Then OutArray = OutArray & vbCRLF
    End If
    Next

    'TEST:
    'alert OutArray



    'Write OutArray to new document:
    'if not editor.EnableTab then
    ' editor.EnableTab = True
    'end if
    editor.NewFile
    document.write OutArray



    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 Function

    HTH? :-D


    @Emura

    But i don’t understand why the function didn’t return something with the function name?

    I think this should work:


    call funcRegEx x y

    If funcRegEx Then alert "OK"

    Function funcRegEx(needle, haystack)
    Set regEx = New RegExp
    regEx.Pattern = needle
    regEx.IgnoreCase = True
    regEx.Global = True
    if regEx.Test(haystack) Then funcRegEx = TRUE
    End Function

    but i have to use something like:


    Dim funcRegExReturn

    call funcRegEx x y
    If funcRegExReturn Then alert "OK"

    Function funcRegEx(needle, haystack)
    Set regEx = New RegExp
    regEx.Pattern = needle
    regEx.IgnoreCase = True
    regEx.Global = True
    if regEx.Test(haystack) Then funcRegExReturn = TRUE
    End Function

    10.1.0, 32-bit portable on XP 32 SP3

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Regular Expressions’ is closed to new topics and replies.