(regexp: RegExp)
| 152 | } |
| 153 | |
| 154 | export function regExpLeadsToEndlessLoop(regexp: RegExp): boolean { |
| 155 | // Exit early if it's one of these special cases which are meant to match |
| 156 | // against an empty string |
| 157 | if (regexp.source === '^' || regexp.source === '^$' || regexp.source === '$' || regexp.source === '^\\s*$') { |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | // We check against an empty string. If the regular expression doesn't advance |
| 162 | // (e.g. ends in an endless loop) it will match an empty string. |
| 163 | const match = regexp.exec(''); |
| 164 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 165 | return !!(match && <any>regexp.lastIndex === 0); |
| 166 | } |
| 167 | |
| 168 | export const DefaultWordPattern = |
| 169 | /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g; |
no test coverage detected