Add back regex support

This commit is contained in:
Dan Abramov
2019-04-04 17:05:34 +01:00
parent 0f0062a71c
commit 2afda3de37
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ export default function SearchInput(props: Props) {
onChange={handleTextChange}
onKeyDown={handleKeyDown}
onKeyPress={handleInputKeyPress}
placeholder="Search"
placeholder="Search (text or /regex/)"
ref={inputRef}
value={searchText}
/>
+17
View File
@@ -6,6 +6,23 @@ import { meta } from '../../hydration';
import type { HooksTree } from 'src/backend/types';
export function createRegExp(string: string): RegExp {
// Allow /regex/ syntax with optional last /
if (string[0] === '/') {
// Cut off first slash
string = string.substring(1);
// Cut off last slash, but only if it's there
if (string[string.length - 1] === '/') {
string = string.substring(0, string.length - 1);
}
try {
return new RegExp(string, 'i');
} catch (err) {
// Bad regex. Make it not match anything.
// TODO: maybe warn in console?
return new RegExp('.^');
}
}
function isLetter(char: string) {
return char.toLowerCase() !== char.toUpperCase();
}