react-highlight-regex

Highlight texts with regex!

Usage no npm install needed!

<script type="module">
  import reactHighlightRegex from 'https://cdn.skypack.dev/react-highlight-regex';
</script>

README

React highlight regex

Highlight texts with regex!

This packages needs String.prototype.matchAll to work properly. Check out availability on caniuse before use.

Example and Usage

Codesandbox Demo

$ yarn add react-highlight-regex
import * as React from 'react';
import { Highlight } from 'react-highlight-regex';

function BasicUsage() {
  return (
    <Highlight match={/a|t/} text="An apple a day keeps the doctor away." />
  );
}

Props

name type description
text string The text to be highlighted.
match RegExp Regular expression for content to be highlighted
highlightClassname string(optional) Classname for highlighted parts