PageSourceSearch

https://python-fiddle.com/_nuxt/DX8vc8cx.js

js python-fiddle.com collected 2026-09-24 12:13:19 UTC 9,318 bytes, 25 lines download raw bytes

1import F from"./BJKvMJ2_.js";import H from"./DYiKc8Cq.js";import O from"./BiPjllOI.js";import W from"./CF-xxtxl.js";import X from"./CWbIKBpY.js";import{_ as Q}from"./DEWBa1i1.js";import{c as r,o,j as e,v as J,x as K,r as x,P as Y,b as C,l as ee,e as te,B as ae,z as ne,a as i,w as p,t as u,u as n,i as E,D as se,F as g,q as f,m as N,s as _,T as oe}from"#entry";import{_ as re}from"./DlAUqK2U.js";import{g as ie,S as le,M as ce,b as ue}from"./DOtugtlZ.js";import{r as de}from"./CBNZ-g5F.js";import"./DFuKEkiz.js";import"./IljeZfEr.js";import"./DOBxUZCA.js";import"./DLTAocxR.js";import"./CBRtWl27.js";import"./CJ5NhiWv.js";import"./Bf_2DgNn.js";import"./Bv_fBYKe.js";import"./Bd_6KxB9.js";import"./DBijBH7F.js";import"./L8MxqQP2.js";import"./CaeU2FrJ.js";function pe(T,v){return o(),r("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"1.5",stroke:"currentColor","aria-hidden":"true","data-slot":"icon"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M13.5 6H5.25A2.25 2.25 0 0 0 3 8.25v10.5A2.25 2.25 0 0 0 5.25 21h10.5A2.25 2.25 0 0 0 18 18.75V10.5m-10.5 6L21 3m0 0h-5.25M21 3v5.25"})])}function me(T,v){return o(),r("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24","stroke-width":"1.5",stroke:"currentColor","aria-hidden":"true","data-slot":"icon"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round",d:"M7.217 10.9
107a2.25 2.25 0 1 0 0 2.186m0-2.186c.18.324.283.696.283 1.093s-.103.77-.283 1.093m0-2.186 9.566-5.314m-9.566 7.5 9.566 5.314m0 0a2.25 2.25 0 1 0 3.935 2.186 2.25 2.25 0 0 0-3.935-2.186Zm0-12.814a2.25 2.25 0 1 0 3.933-2.185 2.25 2.25 0 0 0-3.933 2.185Z"})])}const he={class:"mb-8 mx-2 sm:mx-4"},ge={class:"text-center mt-4 sm:mt-8 lg:mt-16"},fe={class:"text-3xl sm:text-5xl font-bold tracking-tight text-default-text-base"},xe={class:"grid grid-cols-1 lg:grid-cols-2 gap-8"},_e={class:"my-4 text-default-text-light"},ve={class:""},ye={key:1},we={class:"text-lg font-bold mt-4"},be={class:"text-default-text-lighter mt-2 px-4"},ke={class:"mt-4 whitespace-pre-wrap text-default-text-light p-4 rounded bg-default-bg-light"},Me={class:"px-1 py-1"},Ce={class:_(["text-default-text-light flex space-x-2 justify-between items-center rounded-md px-2 py-2 text-sm"])},Te={class:"text-xs bg-default-bg-light rounded p-2 overflow-x-scroll whitespace-nowrap grow"},Se={class:"p-4 rounded"},$e={class:"text-lg sm:text-xl font-semibold tracking-tight text-default-text-base"},je={class:"font-bold mr-2 bg-default-bg-light px-2 py-1 rounded"},Ae={__name:"regex",setup(T){const v=J(),S=K(),h=x(S.query.pattern??"em([\\w-]+)@"),m=x(S.query.text??`[email protected]
2[email protected]
3myem#ailad@[email protected]
4`),{page:R}=Y(),y=x(!0),w=C(()=>{const t=new URL(window.location.href);return t.searchParams.set("pattern",h.value),t.searchParams.set("text",m.value),t.href}),$=x([]),j=x(!1),b=C(()=>`import re
5pattern = r"${h.value}"
6text = '''${m.value}'''
7
8output = []
9prev = 0
10for m in re.finditer(pattern, text):
11    output.append((prev, m.start(), "unmatched"))
12    prev = m.start()
13    num_groups = len(m.groups())
14    for group in range(1, num_groups + 1):
15        output.append((prev, m.start(group), "matched"))
16        prev = m.start(group)
17        output.append((prev, m.end(group), "group"))
18        prev = m.end(group)
19    output.append((prev, m.end(), "matched"))
20    prev = m.end()
21
22if output:
23    output.append((prev, len(text), "unmatched"))
24
25output if output else None`);function z(t){if(t.msg_type==="execute_result"){const a=t.content;$.value=a??[]}else t.msg_type==="execute_reply"&&(y.value=!1)}async function A(t){await v.kernel.runCode(t,z,!1,!1)}const{$analytics:B}=ee();te(()=>{setTimeout(async()=>{await A(b.value)},100)}),ae(b,async()=>{y.value=!0,await A(b.value),j.value||(B.track("REGEX_ATTEMPT",{pattern:h.value}),j.value=!0)});function P(t){window.open(t,"_blank","noreferrer")}async function L(){await navigator.clipboard.writeText(w.value)}const I={"Basic Patterns":[{".":"Matches any character except a newline"},{d:"Matches any digit"},{D:"Matches any non-digit character"},{w:"Matches any alphanumeric character"},{W:"Matches any non-alphanumeric character"},{s:"Matches any whitespace character"},{S:"Matches any non-whitespace character"},{"^":"Matches the start of a string"},{$:"Matches the end of a string"}],Quantifiers:[{"*":"Matches zero or more occurrences"},{"+":"Matches one or more occurrences"},{"?":"Matches zero or one occurrence"},{"{n}":"Matches exactly n occurrences"},{"{n,}":"Matches n or more occurrences"},{"{n,m}":"Matches between n and m occurrences"}],"Character Classes":[{"[abc]":"Matches any character in the set (a, b, or c)"},{"[^abc]":"Matches any character not in the set (not a, b, or c)"},{"[a-z]":"Matches any character in the range (a to z)"},{"[A-Z]":"Matches any uppercase character"},{"[0-9]":"Matches any digit"}],"Grouping and Capturing":[{"( )":"Groups multiple patterns together"},{"(?: )":"Non-capturing group"},{"(?P<name> )":"Capturing group with name"}],Anchors:[{"\\b":"Matches a word boundary"},{"\\B":"Matches a non-word boundary"},{"\\A":"Matches the start of a string"},{"\\Z":"Matches the end of a string"}],"Special Characters":[{"\\":"Escapes a special character"},{".":"Matches any character"}]};ne({meta:[{hid:"og:image",property:"og:image",content:"/img/regex.jpg"},{hid:"twitter:image",name:"twitter:image",content:"/img/regex.jpg"},{hid:"og:image:width",property:"og:image:width",content:"1200"},{hid:"og:image:height",property:"og:image:height",content:"630"},{hid:"og:image:type",property:"og:image:type",content:"image/png"}]});function q(t){const a=[];let l=0;for(;l<t.length;)l+2<t.length&&t[l][2]==="matched"&&t[l+1][2]==="group"&&t[l+2][2]==="matched"?(a.push([t[l],t[l+1],t[l+2]]),l+=3):(a.push([t[l]]),l++);return a}const k=C(()=>q($.value));return(t,a)=>{const l=F,D=H,G=O,V=W,U=X,Z=Q;return o(),r("div",null,[i(Z,null,{default:p(()=>[e("div",he,[e("div",ge,[e("h1",fe,u(n(R).title),1),a[4]||(a[4]=e("h2",{class:"mt-4 mb-8 text-xl sm:text-2xl leading-8 text-default-text-lighter"}," Enter a regular expression pattern and a string to test it against ",-1))]),e("div",xe,[e("div",null,[i(l,{label:"Regex pattern",modelValue:n(h),"onUpdate:modelValue":a[0]||(a[0]=s=>E(h)?h.value=s:null),class:"my-4"},null,8,["modelValue"]),i(D,{label:"Test string",modelValue:n(m),"onUpdate:modelValue":a[1]||(a[1]=s=>E(m)?m.value=s:null),rows:6},null,8,["modelValue"]),e("div",_e,[e("div",ve,[n(y)?(o(),se(G,{key:0})):(o(),r("div",ye,[e("h3",we,"Found "+u(n(k).filter(s=>s[0][2]==="matched").length)+" matches",1),e("div",be,[(o(!0),r(g,null,f(n(k).filter(s=>s[0][2]==="matched"),(s,d)=>(o(),r("div",{key:d,class:"my-2"},[N(u(d+1)+": ",1),(o(!0),r(g,null,f(s,(c,M)=>(o(),r("span",{key:M,class:_(c[2])},[e("span",null,u(n(m).slice(c[0],c[1])),1)],2))),128))]))),128))]),e("pre",ke,[(o(!0),r(g,null,f(n(k),(s,d)=>(o(),r("span",{key:d,class:_({"hover-matched":s[0][2]==="matched"})},[(o(!0),r(g,null,f(s,(c,M)=>(o(),r("span",{key:M,class:_(c[2])},[e("span",null,u(n(m).slice(c[0],c[1])),1)],2))),128))],2))),128))])]))])]),i(n(ie),{as:"div",class:"relative inline-block text-left flex justify-end"},{default:p(()=>[e("div",null,[i(n(le),{onClick:a[2]||(a[2]=()=>n(B).track("REGEX_SHARE")),class:"flex justify-center items-center rounded-md bg-indigo-700 hover:bg-indigo-600 px-4 py-1 text-sm font-medium text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75"},{default:p(()=>[a[5]||(a[5]=e("div",{class:"hidden sm:inline-block"},"Share this regex",-1)),i(n(me),{class:"sm:ml-2 h-6 w-6 text-indigo-200 hover:text-indigo-100","aria-hidden":"true"})]),_:1})]),i(oe,{"enter-active-class":"transition duration-100 ease-out","enter-from-class":"transform scale-95 opacity-0","enter-to-class":"transform scale-100 opacity-100","leave-active-class":"transition duration-75 ease-in","leave-from-class":"transform scale-100 opacity-100","leave-to-class":"transform scale-95 opacity-0"},{default:p(()=>[i(n(ce),{class:"z-10 w-80 sm:w-96 absolute right-0 mt-2 origin-top-right divide-y divide-slate-100 rounded-md bg-default-bg-lighter shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"},{default:p(()=>[e("div",Me,[i(n(ue),null,{default:p(({active:s})=>[e("div",Ce,[e("div",Te,u(n(w)),1),i(V,{onClick:L,class:"bg-indigo-700 hover:bg-indigo-600 text-default-text-light hover:text-default-text-base"},{default:p(()=>[i(n(de),{active:s,class:"inline h-6 w-6","aria-hidden":"true"},null,8,["active"])]),_:2},1024),i(V,{onClick:a[3]||(a[3]=d=>
25P(n(w))),class:"bg-slate-300 hover:bg-slate-100 text-slate-900 hover:text-slate-800"},{default:p(()=>[i(n(pe),{active:s,class:"inline h-6 w-6","aria-hidden":"true"},null,8,["active"])]),_:2},1024)])]),_:1})])]),_:1})]),_:1})]),_:1})]),e("div",Se,[a[6]||(a[6]=e("h2",{class:"text-2xl sm:text-3xl font-semibold tracking-tight text-default-text-dark my-4"}," Python Regex Cheat Sheet ",-1)),(o(),r(g,null,f(I,(s,d)=>e("div",{key:d,class:"my-4"},[e("h3",$e,u(d),1),e("ul",null,[(o(!0),r(g,null,f(s,c=>(o(),r("li",{key:c,class:"text-default-text-lighter my-2"},[e("span",je,u(Object.keys(c)[0]),1),N(" "+u(Object.values(c)[0]),1)]))),128))])])),64))])]),i(U)])]),_:1})])}}},Ye=re(Ae,[["__scopeId","data-v-d02eb031"]]);export{Ye as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.