Skip to content

Instantly share code, notes, and snippets.

@jwrigh26
Created October 25, 2021 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwrigh26/4f51652a347ad1b7b220fcd17c89d8d4 to your computer and use it in GitHub Desktop.
Save jwrigh26/4f51652a347ad1b7b220fcd17c89d8d4 to your computer and use it in GitHub Desktop.
Regex Helper Example
// Matches
// values: be90d703-4671-4024-9a20-bf4c42d5 from
// URL: .../accruals.html#/accruals-wizard/be90d703-4671-4024-9a20-bf4c42d5/create
const foo = {
fooIdFromPathname: pathname => {
const regex = new RegExp(
`^(?:.*)(?:(?:herp-dirp\/)|(?:foo\/))([a-zA-z0-9-]*)(?:\/)(?:(?:.*))?`
);
const results = regex.exec(pathname) ?? [];
return results && results.length > 1 ? results[1] : undefined;
},
isEdit: pathname => pathname.includes('edit'),
};
export default {
foo,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment