Pattern matching for strings independent from symbols

那年仲夏 提交于 2019-12-04 13:14:18

I don't think you need regular expressions here. Your search term:

unseen
123442

This has six characters, so index each word of your text into 6-mers

belittle

12,12,12,12,11,12,12 2-mers
123,123,123,122,112,123 3-mers
1234,1234,1233,1223,1123 4-mers
12345,12344,12334,12234 5-mers
123455,123442,123321 6-mers

So just looking at the 6-mers, you've got a match. Any 6 digit number less than your search term would also be a match, to allow for the abcd (1234) case matching an abca (1231) word.

So given a search term of n characters, just split each word into its constituent n-mers and check for numeric equal or less than.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!