Nesting ArkTypes within a regex
Is there a way to put ArkType types within a regex? As an examplewhere for
z
something like hi 3
would be valid, but not hi 13
or hello 5
-- i.e. to be valid, the value passed into z
has to be a string of length 1 or 2, followed by a space, followed by a number 1-9 (inclusive))25 Replies
I know I can do something likewhere
callback
handles the x
and y
, but I'm looking for a direct wayThere's no description, so is that actually what I'm after?
If so, good to know it's on the backlog
You are after
`${x} ${y}`
, right?Hmm, I guess, yeah
I'd like it to work within regexes too
I guess I can add a comment to the issue stating that
How tho?
String type can't be a part of regex in general
...well, it can, but that's complicated
Hmm, I guess it doesn't strictly have to work within regex, but would be nice to have that
Since a regex will always have an equivalent arktype type if this template literal stuff is a thing
for that you need a "complete" regex type
Like
/^\d+$/
. And if you get like /\d+\d+\d+\d+/
that's DDOS
But well, I like your idea of "regex literals"
It's 0<alpha<3
btw
Then it can be inferred as for something along the lines of "221B Baker Street, London, NW1 6XE".
So I guess the equivalent with template literals, would be something likewhich is much tidier and clearer what's going on.
Isn't that different? I think
alpha
is just letters or something, whereas string
is "any string"You MUST use selection groups as you may have narrows and morphs
Yes
Wdym?
integer string is
\d+
, integer<987 is the same, you need to parse it to validate further\d+
isn't the same as integer < 999
though. To be the same it'd have to be \d{1,3}
(and exclude 999 + handle negatives, I guess)Okay, a better case -
0<integer%3<400
Which means "greater than 0, less than 400, and a multiple of 3"?
Right, so is your point that this can't be represented in regex? I.e. need more validation than just a regex