How to use escape-string-regexp - 9 common examples

To help you get started, we’ve selected a few escape-string-regexp 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 expo / snack-web / src / client / components / FileList / FileListChildren.tsx View on Github external
e =>
        // Filter-out non-immediate children
        !e.item.path.replace(new RegExp(`^${escapeRegexp(this.props.parent)}/`), '').includes('/')
    );
github ifiokjr / remirror / @remirror / extension-emoji / src / emoji-extension.ts View on Github external
public suggestions({ getActions }: ExtensionManagerParams): Suggester {
    const {
      suggestionCharacter,
      suggestionKeyBindings,
      maxResults,
      onSuggestionChange,
      onSuggestionExit,
    } = this.options;
    // const fn = debounce(100, sortEmojiMatches);

    return {
      noDecorations: true,
      invalidPrefixCharacters: escapeStringRegex(suggestionCharacter),
      char: suggestionCharacter,
      name: this.name,
      appendText: '',
      suggestTag: 'span',
      keyBindings: suggestionKeyBindings,
      onChange: params => {
        const query = params.queryText.full;
        const emojiMatches = query.length === 0 ? this.frequentlyUsed : sortEmojiMatches(query, maxResults);
        onSuggestionChange({ ...params, emojiMatches });
      },
      onExit: onSuggestionExit,
      createCommand: ({ match }) => {
        const create = getActions('insertEmojiByObject');

        return (emoji, skinVariation) => {
          if (isNullOrUndefined(emoji)) {
github expo / snack-web / src / client / utils / fileUtilities.tsx View on Github external
export function changeParentPath(path: string, oldParentPath: string, newParentPath: string) {
  return path.replace(new RegExp('^' + escapeRegExp(oldParentPath + '/')), newParentPath + '/');
}
github universal-vue / uvue / packages / @uvue / server / plugins / modernBuild.js View on Github external
replaceAssetsTags(html) {
    const assets = [...this.modernManifest.initial, ...this.modernManifest.async];

    for (const asset of assets) {
      if (path.extname(asset) !== '.js') continue;

      const regAsset = new RegExp(
        `<(link|script)\\s[^>]*${escapeStringRegexp(asset)}[^>]*\/?>`,
        'gm',
      );

      let result = regAsset.exec(html);
      while (result !== null) {
        switch (result[1]) {
          case 'link':
            if (result[0].indexOf('preload') > 0) {
              const newTag = result[0].replace('preload', 'modulepreload');
              html = html.replace(result[0], newTag);
            }
            break;
          case 'script':
            const newTag = result[0].replace(/(\/?>)$/, ' type="module"$1');
            html = html.replace(result[0], newTag);
            break;
github GitbookIO / markup-it / src / utils / escape.js View on Github external
function re(str) {
    return new RegExp(escapeStringRegexp(str), 'g');
}
github Thorium-Sim / thorium / src / components / views / Library / index.js View on Github external
.filter(l =>
                    l.title.match(
                      new RegExp(escapeRegex(searchFilter || ""), "gi"),
                    ),
                  )
github Sage / carbon / src / components / menu-list / menu-list.js View on Github external
menuItems() {
    if (this.showMenuItems()) {
      let items = this.props.children;

      if (this.props.filter && this.state.filter) {
        const regex = new RegExp(escapeStringRegexp(this.state.filter), 'i');
        items = items.filter(child => child.props.name.search(regex) > -1);
      }

      return ([
        this.filterHTML(),
        items
      ]);
    }
    return null;
  }
github Feverqwe / tSearch / src / tools / requestQueryDescription.js View on Github external
const findSrcByImgId = (body, id) => {
  const m = new RegExp(`(\\[['"]${escapeStringRegexp(id)}['"]\\])`).exec(body);
  const idPos = body.indexOf(m && m[1]);
  if (idPos === -1) {
    throw new Error('Image id is not found');
  }
  const endPos = body.indexOf('}', idPos);
  let startPos = endPos;
  while (--startPos > 0) {
    if (body.charAt(startPos) === '{') {
      break;
    }
  }
  if (startPos <= 0) {
    throw new Error('Function statement is not found');
  }

  const fnStatement = body.substr(startPos, endPos - startPos);
github Thorium-Sim / thorium / src / components / views / CargoControl / index.js View on Github external
.filter(i =>
                      i.name.match(
                        new RegExp(
                          escapeRegex(this.state.findInventory || ""),
                          "gi",
                        ),
                      ),
                    )

escape-string-regexp

Escape RegExp special characters

MIT
Latest version published 4 years ago

Package Health Score

70 / 100
Full package analysis

Popular escape-string-regexp functions