# Watched word regular expression crash

**URL:** <https://meta.discourse.org/t/watched-word-regular-expression-crash/275701>\
**Category:** Bug\
**Tags:** watched-words\
**Created:** [August 18, 2023, 1:52pm UTC](https://meta.discourse.org/t/watched-word-regular-expression-crash/275701 "2023-08-18T13:52:36Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [August 18, 2023, 1:52pm UTC](https://meta.discourse.org/t/watched-word-regular-expression-crash/275701/1 "2023-08-18T13:52:36Z")

</div>

This is a twofold bug.

First, an error in a regular expression causes a 500 server error when any post is made.  
See also this prior bug report [Invalid regular expressions in 'Watched Words' makes no watched word work](https://meta.discourse.org/t/invalid-regular-expressions-in-watched-words-makes-no-watched-word-work/192160) (scenario: worse).

Second, a previously correct regular expression which escapes a dash, is now seen as incorrect. So where `\-` used to work prior to 3.1.0 stable, it now causes a fatal error.

This is probably happening [because of Unicode being enabled in `9a27803`](https://github.com/discourse/discourse/commit/9a2780397faac09daa1012cd20667e1a30661ae2).

See [Regular expression syntax cheat sheet - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Cheatsheet)

> Note that some characters like `:`, `-`, `@`, etc. neither have a special meaning when escaped nor when unescaped. Escape sequences like `\:`, `\-`, `\@` will be equivalent to their literal, unescaped character equivalents in regular expressions. However, in regular expressions with the [unicode flag](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags), these will cause an _invalid identity escape_ error. This is done to ensure backward compatibility with existing code that uses new escape sequences like `\p` or `\k`.

but it would be nice if there was an exception handler here.

---

_[View the full topic](https://meta.discourse.org/t/watched-word-regular-expression-crash/275701)._
