Viewing 2 posts - 1 through 2 (of 2 total)
- AuthorPosts
- June 18, 2011 at 2:46 pm #9432raviniralMember
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.
July 12, 2011 at 8:34 pm #9457StefanParticipantI don’t know if i do it the elegant way, but at least it works:
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
—
@EmuraBut 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 Functionbut 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
- AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.