1
0
Fork 1
mirror of https://github.com/thatmattlove/hyperglass.git synced 2026-01-22 18:28:07 +00:00
thatmattlove-hyperglass/docs/src/components/RegexPattern.tsx
2021-05-30 15:45:19 -07:00

25 lines
815 B
TypeScript

import * as React from "react";
import { useMemo } from "react";
import Code from "./JSXCode";
const PATTERN_MAP = {
aspath_asdot: String.raw`^(\^|^\_)((\d+\.\d+)\_|(\d+\.\d+)\$|(\d+\.\d+)\(\_\.\+\_\))+$`,
aspath_asplain: String.raw`^(\^|^\_)(\d+\_|\d+\$|\d+\(\_\.\+\_\))+$`,
community_decimal: String.raw`^[0-9]{1,10}$`,
community_extended: String.raw`^([0-9]{0,5})\:([0-9]{1,5})$`,
community_large: String.raw`^([0-9]{1,10})\:([0-9]{1,10})\:[0-9]{1,10}$`,
};
type RegexPatternProps = {
pattern: keyof typeof PATTERN_MAP;
};
const RegexPattern = (
props: React.PropsWithChildren<RegexPatternProps>
): JSX.Element => {
const { pattern } = props;
const thisPattern = useMemo<string>(() => PATTERN_MAP[pattern], [pattern]);
return <Code>'{thisPattern}'</Code>;
};
export default RegexPattern;