CoolFace
Apppublic

admin08077/Githubgemini

sourceHugging Faceotherupdated 10mo agoView on Hugging Face
0likes
RegexSandbox-BVcbnVXq.js3 linesDownload Raw Back to assets
1import{r as i,j as e}from"./react-CIdJ77ke.js";import{z as f,B as N,L as y}from"./index-CX7Qxd1D.js";import"./@braintree-DzxiOROe.js";import"./react-dom-R9L8nDNe.js";import"./scheduler-CoSDG3-6.js";import"./@google-CcUHq7Ay.js";import"./idb-Dob3nYDb.js";import"./marked-BrGMJkBT.js";import"./mermaid-KwKZWwy0.js";import"./dayjs-CeEF-NGT.js";import"./d3-transition-CiCB8KJE.js";import"./d3-timer-DdKHrDhs.js";import"./d3-dispatch-kxCwF96_.js";import"./d3-interpolate-CtIaNujU.js";import"./d3-color-amxIadob.js";import"./d3-selection-C52G7wmG.js";import"./d3-ease-DRPgKoYJ.js";import"./d3-zoom-BYoC3mS3.js";import"./dompurify-J5RlrwSC.js";import"./dagre-d3-es-CTpFWynZ.js";import"./lodash-es-Dt6r0yiR.js";import"./d3-shape-CX8xTzfR.js";import"./d3-path-CimkQT29.js";import"./d3-fetch-BOsq7VnW.js";import"./khroma-DUX6PT6k.js";import"./uuid-DhYbOkY1.js";import"./d3-scale-DRZz3QW5.js";import"./internmap-BkD7Hj8s.js";import"./d3-array-DGRYoJHh.js";import"./d3-format-CzD4bSOQ.js";import"./d3-time-format-CUNN4Ell.js";import"./d3-time-6cSPyVSY.js";import"./d3-axis-DSWTncID.js";import"./elkjs-oKFFZvz7.js";import"./cytoscape-DtBltrT8.js";import"./cytoscape-cose-bilkent-Cgr1thlj.js";import"./cose-base-CwCxnKwh.js";import"./layout-base-CMXQqlmj.js";import"./d3-sankey-DgqkLiUE.js";import"./d3-scale-chromatic-B-NsZVaP.js";import"./ts-dedent-DrFu-skq.js";import"./stylis-D5iaQeiq.js";import"./mdast-util-from-markdown-CLAsVoWb.js";import"./micromark-CTBPIv-_.js";import"./micromark-util-combine-extensions-Bka6Sc1c.js";import"./micromark-util-chunked-DrRIdSP-.js";import"./micromark-factory-space-x2vfxbz5.js";import"./micromark-util-character-Bcm1tP9o.js";import"./micromark-core-commonmark-AH8VCgT7.js";import"./micromark-util-classify-character-Cq7Fg3xE.js";import"./micromark-util-resolve-all-PQCKh0dx.js";import"./decode-named-character-reference-C3-224fz.js";import"./micromark-util-subtokenize-QwsxNXk2.js";import"./micromark-factory-destination-CypD_wgM.js";import"./micromark-factory-label-CRHH4ZHP.js";import"./micromark-factory-title-B7kCBvC9.js";import"./micromark-factory-whitespace-B322EA6O.js";import"./micromark-util-normalize-identifier-C9ANKk3v.js";import"./micromark-util-html-tag-name-DbKNfynz.js";import"./micromark-util-decode-numeric-character-reference-DRnCnno4.js";import"./micromark-util-decode-string-DJl8Y_PO.js";import"./unist-util-stringify-position-Ch_qCilz.js";import"./mdast-util-to-string-C_aolqmU.js";import"./jszip-CFFhfFtd.js";import"./octokit-B6bKu3NB.js";import"./@octokit-MBEWYTsi.js";import"./bottleneck-D_vuF9V7.js";import"./universal-user-agent-CLgqIJsR.js";import"./before-after-hook-y8XtM9xW.js";import"./fast-content-type-parse-3SwieiST.js";const v=[{name:"Email",pattern:"/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/g"},{name:"URL",pattern:"/https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/g"},{name:"IPv4 Address",pattern:"/((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}/g"},{name:"Date (YYYY-MM-DD)",pattern:"/\\d{4}-\\d{2}-\\d{2}/g"}],w=()=>e.jsxs("div",{className:"bg-surface border border-border p-4 rounded-lg",children:[e.jsx("h3",{className:"text-lg font-bold mb-2",children:"Regex Cheat Sheet"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1 text-xs font-mono",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"."})," - Any character"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"\\d"})," - Any digit"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"\\w"})," - Word character"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"\\s"})," - Whitespace"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"[abc]"})," - a, b, or c"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"[^abc]"})," - Not a, b, or c"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"*"})," - 0 or more"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"+"})," - 1 or more"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"?"})," - 0 or one"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"^"})," - Start of string"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"$"})," - End of string"]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-primary",children:"\\b"})," - Word boundary"]})]})]}),Te=({initialPrompt:l})=>{const[p,c]=i.useState("/\\b([A-Z][a-z]+)\\s(\\w+)\\b/g"),[n,u]=i.useState("The quick Brown Fox jumps over the Lazy Dog."),[x,j]=i.useState(l||"find capitalized words and the word after"),[h,g]=i.useState(!1),{matches:a,error:m}=i.useMemo(()=>{try{const r=p.match(/^\/(.*)\/([gimyus]*)$/);if(!r)return{matches:null,error:"Invalid regex literal. Use /pattern/flags."};const[,s,t]=r,o=new RegExp(s,t);return{matches:[...n.matchAll(o)],error:null}}catch(r){return{matches:null,error:r instanceof Error?r.message:"Unknown error."}}},[p,n]),d=i.useCallback(async r=>{if(r){g(!0);try{const s=f(r);let t="";for await(const o of s)t+=o;c(t.trim().replace(/^`+|`+$/g,""))}finally{g(!1)}}},[]);i.useEffect(()=>{l&&d(l)},[l,d]);const b=i.useMemo(()=>{if(!a||a.length===0||m)return n;let r=0;const s=[];return a.forEach((t,o)=>{t.index!==void 0&&(s.push(n.substring(r,t.index)),s.push(e.jsx("mark",{className:"bg-primary/20 text-primary rounded px-1",children:t[0]},o)),r=t.index+t[0].length)}),s.push(n.substring(r)),s},[a,n,m]);return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx(N,{}),e.jsx("span",{className:"ml-3",children:"RegEx Sandbox"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Test your regular expressions and generate them with AI."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-3 gap-6 min-h-0",children:[e.jsxs("div",{className:"lg:col-span-2 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:x,onChange:r=>j(r.target.value),placeholder:"Describe the pattern to find...",className:"flex-grow px-3 py-1.5 rounded-md bg-surface border border-border text-sm focus:ring-2 focus:ring-primary"}),e.jsx("button",{onClick:()=>d(x),disabled:h,className:"btn-primary px-4 py-1.5 flex items-center",children:h?e.jsx(y,{}):"Generate"})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"regex-pattern",className:"text-sm font-medium text-text-secondary",children:"Regular Expression"}),e.jsx("input",{id:"regex-pattern",type:"text",value:p,onChange:r=>c(r.target.value),className:`w-full mt-1 px-3 py-2 rounded-md bg-surface border ${m?"border-red-500":"border-border"} font-mono text-sm focus:ring-2 focus:ring-primary`}),m&&e.jsx("p",{className:"text-red-500 text-xs mt-1",children:m})]}),e.jsxs("div",{className:"flex flex-col flex-grow min-h-0",children:[e.jsx("label",{htmlFor:"test-string",className:"text-sm font-medium text-text-secondary",children:"Test String"}),e.jsx("textarea",{id:"test-string",value:n,onChange:r=>u(r.target.value),className:"w-full mt-1 p-3 rounded-md bg-surface border border-border font-mono text-sm resize-y h-32"}),e.jsx("div",{className:"mt-2 p-3 bg-background rounded-md border border-border min-h-[50px] whitespace-pre-wrap",children:b})]}),e.jsxs("div",{className:"flex-shrink-0",children:[e.jsxs("h3",{className:"text-lg font-bold",children:["Match Groups (",a?.length||0,")"]}),e.jsx("div",{className:"mt-2 p-2 bg-surface rounded-md overflow-y-auto max-h-48 font-mono text-xs border border-border",children:a&&a.length>0?a.map((r,s)=>e.jsxs("details",{className:"p-2 border-b border-border",children:[e.jsxs("summary",{className:"cursor-pointer text-green-700",children:["Match ",s+1,': "',r[0],'"']}),e.jsx("div",{className:"pl-4 mt-1",children:Array.from(r).map((t,o)=>e.jsxs("p",{className:"text-text-secondary",children:["Group ",o,": ",e.jsx("span",{className:"text-amber-700",children:String(t)})]},o))})]},s)):e.jsx("p",{className:"text-text-secondary text-sm p-2",children:"No matches found."})})]})]}),e.jsxs("div",{className:"lg:col-span-1 space-y-4",children:[e.jsx(w,{}),e.jsxs("div",{className:"bg-surface border border-border p-4 rounded-lg",children:[e.jsx("h3",{className:"text-lg font-bold mb-2",children:"Common Patterns"}),e.jsx("div",{className:"flex flex-col items-start gap-2",children:v.map(r=>e.jsx("button",{onClick:()=>c(r.pattern),className:"text-left text-sm text-primary hover:underline",children:r.name},r.name))})]})]})]})]})};export{Te as RegexSandbox};2//# sourceMappingURL=RegexSandbox-BVcbnVXq.js.map3