WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

RegularExpressions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Link Target Checker

 Keywords: HTML A HREF Anchor Link Target Checker System.Text.RegularExpressions.Regex

;***************************************************************************
;**    Link Target Checker
;**
;** Purpose: Checks that a link contains a target="_blank"
;** Inputs:
;** Outputs:
;** Reference:
;**       REQUIRES WinBatch 2013A or newer
;**
;** Developer: Deana Falk 2014.06.02
;***************************************************************************
If Version( )< '2013A'
   Pause('Notice', 'Need 2013A or Newer Version of WinBatch')
   Exit
EndIf

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Load assemblies into the WinBatch process.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ObjectClrOption( 'use', 'System, Version=3.5.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089')

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Prompt for input
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
link = `<a href="somesite">This is the link to some site</a>`
pattern = `<a(((?!target=).)*)">`
replacement = `<a$1" target="_blank">`

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
; Create a class implemented by a managed assembly.
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
oReg = ObjectClrNew('System.Text.RegularExpressions.Regex',pattern)
;oReg.CacheSize = ObjectType("ui2",30) ;2-byte unsigned integer.
If oReg.IsMatch( link )
   newlink = oReg.Replace( link, pattern, replacement )
   Message( link, newlink  )
EndIf
Exit

Article ID:   W18525
Filename:   Link Target Checker.txt
File Created: 2014:06:02:14:49:00
Last Updated: 2014:06:02:14:49:00