Created
October 25, 2021 19:49
-
-
Save jwrigh26/4f51652a347ad1b7b220fcd17c89d8d4 to your computer and use it in GitHub Desktop.
Regex Helper Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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