<commit_before>'use strict'

import React from 'react'

// Returns a React element or a string
function reactHighlight (word, options, wordIndex) {
  const { highlightWords, ...props } = options
  const re = new RegExp(`(^[@]?(${highlightWords.join('|')})[:,]?)$`, 'gi')
  const match = re.test(word)
  props.key = `${word}-${wordIndex}`
  return match ? React.createElement('span', props, word) : word
}

export default reactHighlight<commit_msg>Refactor highlight regex, fixes #125<commit_after>'use strict'

import React from 'react'

// Returns a React element or a string
function reactHighlight (word, options, wordIndex) {
  const { highlightWords, ...props } = options
  const re = new RegExp(`@?(${highlightWords.join('|')})(?!\\w{1})`, 'gu')
  const match = re.test(word)
  props.key = `${word}-${wordIndex}`
  return match ? React.createElement('span', props, word) : word
}

export default reactHighlight
{'fraction_non_alphanumeric': 0.16921397379912664, 'fraction_numerical': 0.004366812227074236, 'mean_word_length': 4.916129032258064, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3623940', 'n_tokens_mistral': 291, 'n_tokens_neox': 280, 'n_words': 85}