How to use the xregexp/xregexp-all.js.build function in xregexp

To help you get started, we’ve selected a few xregexp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Human-Connection / Human-Connection / webapp / middleware / searchHashtag.js View on Github external
export default async ({ store, env, route, redirect }) => {
  let publicPages = env.publicPages
  // only affect non public pages
  if (publicPages.indexOf(route.name) >= 0) {
    return true
  }

  const regX = build('^/search/hashtag/((\\pL+[\\pL0-9]*)|([0-9]+\\pL+[\\pL0-9]*))$')
  const matchHashtag = route.fullPath ? exec(decodeURI(route.fullPath), regX) : null

  if (!matchHashtag) return true

  return redirect(`/?hashtag=${encodeURI(matchHashtag[1])}`)
}
github Human-Connection / Human-Connection / backend / src / middleware / hashtags / extractHashtags.js View on Github external
import cheerio from 'cheerio'
import { exec, build } from 'xregexp/xregexp-all.js'
// formats of a Hashtag:
//   https://en.wikipedia.org/w/index.php?title=Hashtag&oldid=905141980#Style
// here:
//    0. Search for whole string.
//    1. Hashtag has only all unicode characters and '0-9'.
//    2. If it starts with a digit '0-9' than a unicode character has to follow.
const regX = build('^/search/hashtag/((\\pL+[\\pL0-9]*)|([0-9]+\\pL+[\\pL0-9]*))$')

export default function(content) {
  if (!content) return []
  const $ = cheerio.load(content)
  // We can not search for class '.hashtag', because the classes are removed at the 'xss' middleware.
  //   But we have to know, which Hashtags are removed from the content as well, so we search for the 'a' html-tag.
  const urls = $('a')
    .map((_, el) => {
      return $(el).attr('href')
    })
    .get()
  const hashtags = []
  urls.forEach(url => {
    const match = exec(url, regX)
    if (match != null) {
      hashtags.push(match[1])
github Human-Connection / Human-Connection / webapp / components / Editor / Editor.vue View on Github external
sanitizeQuery(query) {
      if (this.suggestionType === HASHTAG) {
        // remove all non unicode letters and non digits
        const regexMatchAllNonUnicodeLettersOrDigits = build('[^\\pL0-9]')
        query = replace(query, regexMatchAllNonUnicodeLettersOrDigits, '', 'all')
        // if the query is only made of digits, make it empty
        return query.replace(/[0-9]/gm, '') === '' ? '' : query
      }
      return query
    },
    // we have to replace our suggestion text with a mention