mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add back regex support
This commit is contained in:
@@ -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}
|
||||
/>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user