Wordle regex solver by Sketch Engine

Helps you solve a Wordle puzzle by generating a regular expression. To look up possible solutions in a word list, Sketch Engine subscription is required (30-day free trial available, no card required).

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Wordle regex solver by Sketch Engine
// @namespace    https://www.sketchengine.eu/
// @version      0.9
// @description  Helps you solve a Wordle puzzle by generating a regular expression. To look up possible solutions in a word list, Sketch Engine subscription is required (30-day free trial available, no card required).
// @author       Marek Blahuš of Lexical Computing
// @match        https://www.nytimes.com/games/wordle/index.html
// @icon         https://www.nytimes.com/games/wordle/images/NYT-Wordle-Icon-32.png
// @grant        none
// ==/UserScript==

/* jshint esversion: 6 */

var board = document.getElementsByTagName('game-app')[0].shadowRoot.getElementById('board');
board.innerHTML += '<div style="text-align: center"><a href="#" id="wordle-regex-ske-link">need help?</a></div>';
board.getElementById('wordle-regex-ske-link').addEventListener('click', wordle_regex_ske);

function wordle_regex_ske(){
  var absents='', presents='', incorrects=Array(5).fill(''), corrects=Array(5).fill('.');
  for(var d of Array.from(Array(6), (_, i) => document.querySelectorAll('game-app')[0].boardState[i] ? Array.from(Array(5), (_, j) => [document.querySelectorAll('game-app')[0].boardState[i][j], document.querySelectorAll('game-app')[0].evaluations[i][j], j]) : []).flat()) {
    switch(d[1]) {
      case "absent": if(!absents.includes(d[0])) absents += d[0]; break;
      case "present": if(!corrects.includes(d[0])) { if(!presents.includes(d[0])) presents += d[0]; if(!incorrects[d[2]].includes(d[0])) incorrects[d[2]] += d[0]; } break;
      case "correct": corrects[d[2]] = d[0]; presents = presents.replace(d[0], ''); incorrects = incorrects.map((v) => v.replace(d[0], '')); break;
      }
  }
  var regex = (absents && corrects.includes('.') ? '(?!.*'+(absents.length>1?'['+absents+']':absents)+')' : '') + (presents.split('').map((v) => '(?=.*'+v+')').join('')) + (incorrects.map((v, i) => v ? '(?!'+'.'.repeat(i)+(v.length>1?'['+v+']':v)+')' : '').join('')) + (corrects.join(''));
  if(confirm('Your regex is:\n'+regex+'\nProceed to Sketch Engine to see a word list? (Login required, free trial available.)')) window.open('https://app.sketchengine.eu/#wordlist?corpname=preloaded%2Fcoca&tab=advanced&keyword='+encodeURIComponent(regex)+'&filter=regex&wlattr=lc&wlminfreq=0&showresults=1&cols=%5B%22frq%22%5D');
}