RegExp
constructor JS-011527// Set up App Shell-style routing, so that all navigation requests
28// are fulfilled with your index.html shell. Learn more at
29// https://developers.google.com/web/fundamentals/architecture/app-shell
30const fileExtensionRegexp = new RegExp('/[^/?]+\\.[^/]+$')31registerRoute(
32 // Return false to exempt requests from being fulfilled by index.html.
33 ({ request, url }: { request: Request; url: URL }) => {
When a regular expression is known in advance, it is considered a best practice to avoid the string literal notation on top of the regular expression notation, and use regular expression literals instead of the constructor function.
// bad practice:
const number = new RegExp("^\d\.$");
// recommended:
const number_ = /^\d\.$/;
Regex literals are easier to read and do not require a call to the RegExp
constructor at runtime.
new RegExp("abc");
new RegExp("abc", "u");
RegExp("abc");
RegExp("abc", "u");
new RegExp("\d\d\.\d\d\.\d\d\d\d");
RegExp(`^\d\.$`);
new RegExp(String.raw`^\d\.$`);
/abc/;
/abc/u;
/\d\d\.\d\d\.\d\d\d\d/;
/^\d\.$/;
// RegExp constructor is allowed for dynamically generated regular expressions
new RegExp(pattern);
RegExp("abc", flags);
new RegExp(prefix + "abc");
RegExp(`${prefix}abc`);
new RegExp(String.raw`^\d\. ${sufix}`);