Regex for words that can be shortened

What regular expression pattern can I use to match words that can be shortened by leaving letters at the end?

For example, suppose the word "internationalization" and I want to match any of the following:

internationalization internationalizatio internationalizati internationalizat internationaliza internationaliz internationali international internationa internation internati internat 

Or if the word "punctuation"

 punctuation punctuatio punctuati punctuat punctua punctu punct 

What is the best way to do this? I know I can do something like

 punctuation|punctuatio|punctuati|punctuat|punctua|punctu|punct 

but I hope there will be a more elegant way.

+4
source share
3 answers

You can do this in most cases.

 punct(u(a(t(i(on?)?)?)?)?)? internat(i(o(n(a(l(i(z(a(t(i(on?)?)?)?)?)?)?)?)?)?)?)? 
+4
source

Try the following:

 punct(u(a(t(i(o(n)?)?)?)?)?)? 
+1
source

This is not really a regular expression, but I think itโ€™s easier to solve it with a simple String.prototype.indexOf method

'punctuation'.indexOf(str) >= 0

0
source

Source: https://habr.com/ru/post/1442897/


All Articles