Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 540 Bytes

README.md

File metadata and controls

36 lines (30 loc) · 540 Bytes

useRegex

A react hook for processing regular expressions.


How to use

Install react-use-regex:

# npm
npm install react-use-regex

# yarn
yarn add react-use-regex

Import and enjoy!

import useRegex from 'react-use-regex'

function MyComponent() {
  const [
    isMatch, 
    matches, 
    indexOfFirstMatch, 
    replace
  ] = useRegex(/R.*?x/i, 'Hello, Regex!')

  // isMatch: true
  // matches: ['Regex']
  // indexOfFirstMatch: 7
  // replace('World') => 'Hello, World!'

  return (
    <h1>...</h1>
  )
}