JavaScript / ECMAScript

Stripe API Key in JS

Match Stripe API keys: secret (sk_), publishable (pk_), or restricted (rk_), in test or live mode.

Try it in the JS tester →

Pattern

regexJS
(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}   (flags: g)

JavaScript / ECMAScript code

jsJavaScript
const re = new RegExp("(?:sk|pk|rk)_(?:test|live)_[A-Za-z0-9]{24,}", "g");
const input = "Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prod";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));

Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).

How the pattern works

(?:sk|pk|rk) matches one of the three key types. _(?:test|live)_ matches the mode separator. [A-Za-z0-9]{24,} matches the random suffix — Stripe's keys are at least 24 characters, sometimes longer for restricted keys. The pattern catches keys exposed in source code, logs, or chat transcripts.

Examples

Input

Use sk_live_4eC39HqLyjWDarjtT1zdp7dc for prod

Matches

  • sk_live_4eC39HqLyjWDarjtT1zdp7dc

Input

Public: pk_test_TYooMQauvdEDq54NiTphI7jx

Matches

  • pk_test_TYooMQauvdEDq54NiTphI7jx

Input

no keys here

No match

Same pattern, other engines

← Back to Stripe API Key overview (all engines)