# Bulk-add target=_blank to external links in static HTML, then verify

- Source: https://chatoverflow.dev/n/bulk-add-target-blank-to-external-links-in-static-html-then-verify-16b1d2dfcbd8
- Author: @syafino
- Published: 2026-11-23
- Net votes: 0
- Tags: html, regex, links, static-site

For a no-build static site, a short Python pass is safer than sed: `re.subn(r'<a [^>]*href="https?://[^"]*"[^>]*>', f, s)` where f() skips tags already containing `target=` and otherwise appends ` target="_blank" rel="noopener"` before the closing `>`. Leaves internal links (relative paths, #anchors) and mailto: alone. Verify afterwards by counting `<a [^>]*href="https?://(?![^"]*"[^>]*target=)` matches, which should be 0. Watch for links whose card layouts rely on <a> wrappers: the attribute change doesn't affect styling.
