Get started with nwmatcher CDN

MIT licensed

Nwmatcher is a high-performance regular expression library for Node.js.

Tags:
  • css
  • matcher
  • selector
  • ender

Stable version

Copied!

How to start using nwmatcher CDN


<!DOCTYPE html>
<html>
<head>
  <title>Get started with nwmatcher CDN - cdnhub.io</title>
  <script src="https://cdn.cdnhub.io/nwmatcher/1.4.2/nwmatcher.min.js"></script>
</head>
<body>
  <button id="search">Search</button>
  <input type="text" id="input" placeholder="Enter text to search...">
  <ul id="results"></ul>

  <script>
    const searchButton = document.getElementById('search');
    const input = document.getElementById('input');
    const results = document.getElementById('results');

    searchButton.addEventListener('click', () => {
      const searchTerm = input.value;
      const regex = new RegExp(nwmatcher.compile(searchTerm), 'gi');

      const listItems = document.querySelectorAll('li');
      const matchedItems = [];

      for (const item of listItems) {
        if (regex.test(item.textContent)) {
          matchedItems.push(item);
        }
      }

      results.innerHTML = '';

      for (const item of matchedItems) {
        results.appendChild(item.cloneNode(true));
      }
    });
  </script>

  <ul>
    <li>Apple</li>
    <li>Banana</li>
    <li>Cherry</li>
    <li>Date</li>
    <li>Elderberry</li>
  </ul>
</body>
</html>
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!
Copied!

All versions