Regex Golf

Write the shortest regular expression that matches every string in one list and rejects every string in the other. Twelve levels, live feedback, lower score wins.

정규식 골프

한쪽 목록의 모든 문자열은 매치하고 다른 쪽 목록은 전부 거부하는, 가장 짧은 정규식을 작성하세요. 12개 레벨, 실시간 피드백, 짧을수록 승리.

Level 1 / 12

/ /

Must match

    Must reject

      More fun & tests

      All Fun & Tests tools

      About regex golf

      Regex golf is a classic programming puzzle: you are given two lists of strings and must write one regular expression that matches everything in the first list while matching nothing in the second. The catch is length. Your score is the number of characters in the pattern, and like real golf a lower score is better. This version runs entirely in your browser using the JavaScript RegExp engine, gives you 12 levels of increasing difficulty, and shows a green tick or red cross next to every test string as you type so you can see exactly which cases your pattern still gets wrong.

      The levels start with a plain literal substring and build up through the anchors ^ and $, character classes like [0-9] and [^aeiou], alternation, the quantifiers *, +, ? and {n}, lookahead, and finally backreferences such as (.)\1. It is a compact way to learn regular expressions or to warm up before writing a tricky pattern for real work. No signup, no tracking of your answers, and your best run is stored only in your own browser.

      정규식 골프 소개

      정규식 골프는 고전적인 프로그래밍 퍼즐입니다. 두 개의 문자열 목록이 주어지고, 첫 번째 목록의 모든 항목은 매치하면서 두 번째 목록은 하나도 매치하지 않는 정규식 하나를 작성해야 합니다. 핵심은 길이입니다. 점수는 패턴의 문자 수이며, 실제 골프처럼 점수가 낮을수록 좋습니다. 이 버전은 브라우저의 JavaScript RegExp 엔진으로 완전히 브라우저에서 실행되고, 난이도가 점점 높아지는 12개 레벨을 제공하며, 입력하는 동안 각 테스트 문자열 옆에 초록 체크 또는 빨간 X 를 표시해 어떤 경우가 아직 틀렸는지 바로 확인할 수 있습니다.

      레벨은 단순 리터럴 부분 문자열로 시작해 앵커 ^·$, [0-9]·[^aeiou] 같은 문자 클래스, 선택(alternation), 수량자 *·+·?·{n}, 룩어헤드, 마지막으로 (.)\1 같은 역참조까지 단계적으로 확장됩니다. 정규식을 배우거나 실무에서 까다로운 패턴을 작성하기 전에 몸을 푸는 데 좋은 방법입니다. 가입도, 답안 추적도 없으며, 최고 기록은 본인 브라우저에만 저장됩니다.

      How to play

      1. Read the challenge

      Each level describes a rule and shows two lists: strings your regex must match and strings it must reject.

      2. Type a pattern

      Type your regex between the slashes. Every test string gets a live green tick or red cross. Toggle the i, m and g flags if you need them.

      3. Solve it, then shorten it

      The level clears once all match and all reject cases are green. Your score is the character count, so try to trim it before moving on.

      4. Clear all 12

      Advance with Next level. At the end you get total characters used and average per level; your best full run is saved locally.

      플레이 방법

      1. 문제 읽기

      각 레벨은 규칙을 설명하고 두 목록을 보여줍니다: 정규식이 매치해야 하는 문자열과 거부해야 하는 문자열.

      2. 패턴 입력

      슬래시 사이에 정규식을 입력하세요. 각 테스트 문자열에 실시간으로 초록 체크 또는 빨간 X 가 표시됩니다. 필요하면 i, m, g 플래그를 켜세요.

      3. 풀고 나서 줄이기

      매치·거부 항목이 모두 초록이 되면 레벨 통과입니다. 점수는 문자 수이므로 넘어가기 전에 최대한 줄여 보세요.

      4. 12개 전부 클리어

      다음 레벨 버튼으로 진행합니다. 마지막에 총 사용 문자 수와 레벨당 평균이 표시되고, 최고 완주 기록은 로컬에 저장됩니다.

      Frequently asked questions

      Regex golf is a puzzle where you write the shortest possible regular expression that matches every string in one list and matches none of the strings in a second list. Like golf, a lower score wins, so the score is the number of characters in your pattern. It is a popular way to practice regex because each level forces you to think about which feature (an anchor, a character class, alternation, a quantifier) expresses the rule most compactly.
      Practice on small, focused problems like the levels here, and after solving each one try to shorten it. Learn the core building blocks in order: literals, the anchors ^ and $, character classes such as [a-z] and [^aeiou], alternation with the pipe, the quantifiers * + ? and {n}, groups, lookahead, and backreferences. Read other people's short solutions, keep a cheat sheet nearby, and always test your pattern against strings that should fail, not just the ones that should pass.
      There is rarely one canonical answer. The shortest regex depends entirely on the two lists: you only need a pattern that separates the match list from the reject list, so a single literal substring often beats a fully anchored, precise expression. Look for a character or sequence that appears in every string you must match and in none you must reject. That is why in golf a loose pattern frequently scores better than a strict one.
      The habit of finding the minimal pattern is useful, but the golf mindset is not. Production regexes should be readable, anchored where it matters, and safe against edge cases and catastrophic backtracking, even if that costs extra characters. Treat regex golf as a gym for learning what each feature does and how patterns compose, then write clear, well-commented expressions in real code.
      This game uses the JavaScript regular expression engine built into your browser, via the RegExp constructor. That means ECMAScript syntax: character classes, alternation, greedy and lazy quantifiers, capture groups, backreferences like \1, and lookahead are all supported, and lookbehind works in modern browsers. There are no Perl or PCRE extras such as possessive quantifiers or recursion. You can toggle the i, m and g flags; g does not change a match test but is shown for completeness.

      자주 묻는 질문

      정규식 골프는 한 목록의 모든 문자열은 매치하고 두 번째 목록은 하나도 매치하지 않는, 가능한 한 짧은 정규식을 작성하는 퍼즐입니다. 골프처럼 점수가 낮을수록 이기며, 점수는 패턴의 문자 수입니다. 각 레벨마다 어떤 기능(앵커, 문자 클래스, 선택, 수량자)이 규칙을 가장 간결하게 표현하는지 고민하게 만들기 때문에 정규식 연습에 인기가 많습니다.
      여기 레벨처럼 작고 집중된 문제로 연습하고, 하나를 풀 때마다 더 짧게 만들어 보세요. 핵심 구성 요소를 순서대로 익히세요: 리터럴, 앵커 ^ 와 $, [a-z]·[^aeiou] 같은 문자 클래스, 파이프를 이용한 선택, 수량자 * + ? 와 {n}, 그룹, 룩어헤드, 역참조. 남들의 짧은 풀이를 읽고, 치트 시트를 곁에 두고, 통과해야 하는 문자열뿐 아니라 실패해야 하는 문자열로도 항상 테스트하세요.
      정답이 하나로 정해진 경우는 드뭅니다. 가장 짧은 정규식은 두 목록에 전적으로 달려 있습니다. 매치 목록과 거부 목록을 구분하기만 하면 되므로, 완전히 앵커링된 정밀한 표현보다 단일 리터럴 부분 문자열이 더 나을 때가 많습니다. 매치해야 하는 모든 문자열에는 있고 거부해야 하는 문자열에는 없는 문자나 시퀀스를 찾으세요. 골프에서 느슨한 패턴이 엄격한 패턴보다 점수가 좋은 이유입니다.
      최소 패턴을 찾는 습관은 유용하지만, 골프식 사고방식은 그렇지 않습니다. 실무 정규식은 읽기 쉽고, 중요한 곳에 앵커가 있으며, 엣지 케이스와 파국적 백트래킹에 안전해야 합니다. 문자 몇 개가 늘더라도 말이죠. 정규식 골프는 각 기능이 무엇을 하고 패턴이 어떻게 결합되는지 배우는 연습장으로 쓰고, 실제 코드에서는 명확하고 주석이 잘 달린 표현을 작성하세요.
      이 게임은 브라우저에 내장된 JavaScript 정규식 엔진을 RegExp 생성자로 사용합니다. 즉 ECMAScript 문법입니다: 문자 클래스, 선택, 탐욕적·게으른 수량자, 캡처 그룹, \1 같은 역참조, 룩어헤드가 모두 지원되고 최신 브라우저에서는 룩비하인드도 동작합니다. 소유 수량자나 재귀 같은 Perl·PCRE 확장은 없습니다. i, m, g 플래그를 켤 수 있으며, g 는 매치 테스트 결과를 바꾸지 않지만 참고용으로 표시됩니다.
      Sponsor
      Get started on Vultr
      Get $300 free credit — valid for 30 days (limited-time offer)
      Claim your credit →