vamtiger-regex-html-stylesheet-link

A regular expression to match a HTML stylesheet link for defined HTML document text.

Usage no npm install needed!

<script type="module">
  import vamtigerRegexHtmlStylesheetLink from 'https://cdn.skypack.dev/vamtiger-regex-html-stylesheet-link';
</script>

README

VAMTIGER Regex HTML Stylesheet Link

A regular expression to match a HTML stylesheet link for defined HTML document text.

Installation

VAMTIGER Regex HTML Stylesheet Link can be installed using npm or yarn:

npm i --save vamtiger-regex-html-stylesheet-link

or

yarn add vamtiger-regex-html-stylesheet-link

Usage

Import or require a referece to VAMTIGER Regex HTML Stylesheet Link:

import regex from 'vamtiger-regex-html-stylesheet-link';

or

const regex = require('vamtiger-regex-html-stylesheet-link').default;

VAMTIGER Regex HTML Stylesheet Link can be used to match a HTML stylesheet link for defined HTML document text:

const regex = require('vamtiger-regex-html-stylesheet-link').default;

const input = `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>
        Some HTML Title
    </title>
    <link href="some/stylesheet/link/index.css" rel="stylesheet">
</head>
<body>
    <div>
        Some HTML body inner HTML
    </div>
</body>
</html>`;
const match = input.match(regex);

/**
 * if (match) {
 *     // Yep, the input string has a HTML title
 *     match[1] === '<link href="some/stylesheet/link/index.css" rel="stylesheet">'
 * }
 **/

Named capture groups can be referenced when used together with XRegExp:

const XRegExp = require('xregexp');
const regex = require('vamtiger-regex-html-stylesheet-link').default;
const input = `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>
        Some HTML Title
    </title>
    <link href="some/stylesheet/link/index.css" rel="stylesheet">
</head>
<body>
    <div>
        Some HTML body inner HTML
    </div>
</body>
</html>`;
const match = XRegExp.exec(input, regex);
// const match: Match = XRegExp.exec(input, regex); // Typescript

/**
 * if (match) {
 *     // Yep, the input string has a HTML title
 *     match.styleSheetLink === '<link href="some/stylesheet/link/index.css" rel="stylesheet">'
 * }
 **/