MCPcopy Create free account
hub / github.com/Wscats/vscode-explore / createRegExp

Function createRegExp

contributes/src/vs/base/common/strings.ts:190–220  ·  view source on GitHub ↗
(searchString: string, isRegex: boolean, options: RegExpOptions = {})

Source from the content-addressed store, hash-verified

188}
189
190export function createRegExp(searchString: string, isRegex: boolean, options: RegExpOptions = {}): RegExp {
191 if (!searchString) {
192 throw new Error('Cannot create regex from empty string');
193 }
194 if (!isRegex) {
195 searchString = escapeRegExpCharacters(searchString);
196 }
197 if (options.wholeWord) {
198 if (!/\B/.test(searchString.charAt(0))) {
199 searchString = '\\b' + searchString;
200 }
201 if (!/\B/.test(searchString.charAt(searchString.length - 1))) {
202 searchString = searchString + '\\b';
203 }
204 }
205 let modifiers = '';
206 if (options.global) {
207 modifiers += 'g';
208 }
209 if (!options.matchCase) {
210 modifiers += 'i';
211 }
212 if (options.multiline) {
213 modifiers += 'm';
214 }
215 if (options.unicode) {
216 modifiers += 'u';
217 }
218
219 return new RegExp(searchString, modifiers);
220}
221
222export function regExpLeadsToEndlessLoop(regexp: RegExp): boolean {
223 // Exit early if it's one of these special cases which are meant to match

Callers

nothing calls this directly

Calls 1

escapeRegExpCharactersFunction · 0.85

Tested by

no test coverage detected