如何构建一个不关心位置的正则表达式
我正在用 HTML 和 Javascript 制作一个 Scrabble 游戏,我想添加一个基于玩家机架的“提示词”功能。 我有一个包含有效单词的字典数组,我需要根据玩家可用的图块来测试它们,但我不知道如何做一个正则表达式,它给我以下输出:
假设玩家有 DGOGI-*-E瓷砖和正则表达式应该返回:
doggies = True(因为通配符) 血腥=真实 狗=真 神=真 dodge = false(因为D只出现一次)
顺序并不重要,重要的是字母和字母重复的次数
我已经尝试使用 regexpal.com 中的 /[DGOGIE]/ 等有效字母来构建它但它根本不起作用 我也尝试玩这个 (?=.*a)(?=.*b)(?=.*c) 但还是没有结果
I'm making a Scrabble game with HTML and Javascript and I'd like to add a "hint word" feature based on the player's rack.
I have a dictionary array with the valid words, and I need to test them against the players available tiles but I couldn't figure out how to do a regexp that gives me the following output:
Lets say the player has D-G-O-G-I-*-E tiles and the Regexp should return:
doggies = True (because of the wildcard)
gore = True
dog = True
god = true
dodge = false (because D appears only once)
It doesn't matter the order, only the letters and the times that letter is repeated
I've already tried building it with the valid letters like this /[DGOGIE]/ in regexpal.com but it didn't work at all
I also tried playing with this
(?=.*a)(?=.*b)(?=.*c)
but still no result
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定如何使用正则表达式执行此操作,但这是@Felix 描述的解决方案:
(抱歉,我回答得太晚了)
I'm not quite sure how you would do this with regex, but here is the solution that @Felix described:
(Sorry if I answered too late)