Include XRegExp unicode-categories.js client-side

NodeBB Plugins
  • I need additional XRegExp addons for my plugin's client script (to support character categories like \pN). It appears NodeBB includes xregexp (core) and unicode-base by default; how can I add unicode-categories?

    I've tried adding ../../public/vendor/xregexp/unicode/unicode-categories.js to my plugin's scripts as well as modules to no avail (my understanding of what modules is used for is a little fuzzy). In any case, I get "SyntaxError: Unknown Unicode token \pN" when the script runs.

    \pL works fine, presumably because that's provided in unicode-base.


  • How have you tried adding public/vendor/xregexp/unicode/unicode-categories.js to the plugin? You should be able to append it by adding the entry into the plugin's clientScripts array in plugin.json

  • Just to clarify, I believe Julian is talking about copying the script file into your plugin, and trying it that way.

  • Oh, yeah that'd work. I'm not sure if you could link back via relative path to the script in core, though. Worth trying.

  • No luck trying clientScripts (neither the base path as you have it, nor prefixed with "../.."). I don't see clientScripts in the docs... how is that different from scripts?

    Copying the script into my plugin is an acceptable workaround, I suppose.

  • Oh wait! Fixed it. It appears the issue was simply script initialization order. My plugin.json now has this:

    "scripts": [

    (Where main.js is my script that uses XRegExp.) And it works fine. The first time I tried this, the scripts were in reverse order. No need to copy the script into my plugin, though that did help me figure out the issue. Thanks for the suggestion!

  • To date you're the only other person who needed XRegExp, so feel special I guess?

  • Attempting to do Unicode-friendly text manipulation is the worst kind of special. 😫

  • Ha! Yeah I hear you. Every time I load up a regex library I feel like there ought to be a better way... luckily I'm at least semi-proficient at writing a regular expression, but don't ask me to make sense of one after a week's time LOL

Suggested Topics