regex - Automatic compression of a string as a regular expression -


given set of strings, automatically compress each string minimum length regular expression. regular expression 2 different strings should same if these strings identical.

for example:

string 1: abccccccccabccccccccccbbc = (ab[c]{8}){2}ccbbc

string 2: abccccabccccccccccbbc = (ab[c]{4}){2}c{6}bbc

*this example of compression mean though may not shortest way of doing it.

note string length matters: there no need use b{2} represent string bb takes more characters.

is there established method doing this?

an answer pointer academic investigations problem explanation and/or solution problem, whether theoretical, or implementation. in latter case, prefer if implementation in java.

not same example, , not minimal in size, 1 approach.

"abccccccccabccccccccccbbc".replace(/(([a-z])\2{3,})/g,function($0,$1,$2){return $2+$1.length}).replace(/(\d+)/g,'{$1}') "abc{8}abc{10}bbc"  "abccccabccccccccccbbc".replace(/(([a-z])\2{3,})/g,function($0,$1,$2){return $2+$1.length}).replace(/(\d+)/g,'{$1}') "abc{4}abc{10}bbc" 

Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -