# Write efficient, error-free and safe regular expressions in JavaScript and TypeScript

**URL:** <https://community.sonarsource.com/t/write-efficient-error-free-and-safe-regular-expressions-in-javascript-and-typescript/47720>\
**Category:** Sonar Updates\
**Tags:** regex, typescript, javascript\
**Created:** [August 6, 2021, 1:21pm UTC](https://community.sonarsource.com/t/write-efficient-error-free-and-safe-regular-expressions-in-javascript-and-typescript/47720 "2021-08-06T13:21:04Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Alexandre\_Gigleux](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/alexandre_gigleux/32/26_2.png) [@Alexandre\_Gigleux](https://community.sonarsource.com/u/Alexandre_Gigleux)\
**Post date:** [September 15, 2021, 12:28pm UTC](https://community.sonarsource.com/t/write-efficient-error-free-and-safe-regular-expressions-in-javascript-and-typescript/47720/2 "2021-09-15T12:28:46Z")

</div>

Hello,

On top of these rules, we added 8 more to really make sure you have efficient and error-free regexp.  
Here is the list of added rules.

Bug Detections:

- [S6351](https://rules.sonarsource.com/javascript/RSPEC-6351): Regular expressions with the global flag should be used with caution
- [S5867](https://rules.sonarsource.com/javascript/RSPEC-5867): Regular expressions with Unicode property escapes should set Unicode flag
- [S5842](https://rules.sonarsource.com/javascript/RSPEC-5842): Repeated patterns in regular expressions should not match the empty string

Code Smell Detections:

- [S5869](https://rules.sonarsource.com/javascript/RSPEC-5869): Character classes in regular expressions should not contain the same character twice
- [S6019](https://rules.sonarsource.com/javascript/RSPEC-6019): Reluctant quantifiers in regular expressions should be followed by an expression that can’t match the empty string
- [S5843](https://rules.sonarsource.com/javascript/RSPEC-5843): Regular expressions should not be too complicated
- [S6353](https://rules.sonarsource.com/javascript/RSPEC-6353): Regular expression quantifiers and character classes should be used concisely

Security Hotspots Detection:

- [S5852](https://rules.sonarsource.com/javascript/RSPEC-5852): Using slow regular expressions is security-sensitive

Alex

---

_[View the full topic](https://community.sonarsource.com/t/write-efficient-error-free-and-safe-regular-expressions-in-javascript-and-typescript/47720)._
