在Ruby中将类似模式的字符串分组

Lam*_*mnk 3 ruby arrays string algorithm

我有一个文件名数组.这些的子集可能具有类似的模式(字母表末尾带有数字的字符串):

arr = %w[
  WordWord1.html
  WordWord3.html
  WordWord10.html
  WordWord11.html
  AnotherWord1.html
  AnotherWord2.html
  FileFile.html
]
Run Code Online (Sandbox Code Playgroud)

如何识别相似的子串(它们具有相同的子串,只是它们的数字不同)并将它们移动到一个数组?

['WordWord1.html', 'WordWord3.html', 'WordWord10.html', 'WordWord11.html']
['AnotherWord1.html', 'AnotherWord2.html']
['FileFile.html']
Run Code Online (Sandbox Code Playgroud)

fgb*_*fgb 7

arr.group_by { |x| x[/[a-zA-Z]+/] }.values
Run Code Online (Sandbox Code Playgroud)