regextokens icon indicating copy to clipboard operation
regextokens copied to clipboard

OpenAI Service-ID / Service-Key Format

Open odomojuli opened this issue 7 months ago • 0 comments

This is the current expression for service-id:

^[A-Za-z0-9]+(-*[A-Za-z0-9]+)*$

I want to plug in the above expression into the below expression.

This is the current expression for service-key:

sk-{SERVICE ID}-[A-Za-z0-9]{20}T3BlbkFJ[A-Za-z0-9]{20}

service-id can only contain alphanumeric [A-Za-z0-9] or any number of dashes -, but the last character cannot be a dash. My idea is this: First, initial chunk is always alphanumeric [A-Za-z0-9] of length 0-to-N. Then, remaining chunks would be some combination of -, and [A-Za-z0-9]. Finally, the remaining chunks are captured by the greedy quantifier *.

Plugging this into the parent expression causes catastrophic backtracking. I would like to avoid the recursive or the greedy approach for this reason.

Here are some test strings for service-id:

abc123
abc123-
-abc123
abc-123
abc--123
-abc-123
abc-123-
-abc-123-
-
--

odomojuli avatar Jul 04 '24 19:07 odomojuli