Skip to content

Commit dc32290

Browse files
author
Tom Lienard
authored
feat(regex): add cidr regex (#982)
1 parent d102fa2 commit dc32290

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

packages/regex/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ const v6 = `
5454
.replace(/\n/g, '')
5555
.trim()
5656

57+
// Pasted from `cidr-regex` package (https://github.com/silverwind/cidr-regex/blob/master/index.js)
58+
const cidrv4 = `${v4}\\/(3[0-2]|[12]?[0-9])`
59+
const cidrv6 = `${v6}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`
60+
5761
export const ip = new RegExp(`^(?:${v4}|${v6})$`)
5862
export const ipv4 = new RegExp(`^${v4}$`)
5963
export const ipv6 = new RegExp(`^${v6}$`)
64+
export const ipCidr = new RegExp(`(?:^${cidrv4}$)|(?:^${cidrv6}$)`)
65+
export const ipv4Cidr = new RegExp(`^${cidrv4}$`)
66+
export const ipv6Cidr = new RegExp(`^${cidrv6}$`)

0 commit comments

Comments
 (0)