php - Find longest repeating strings? -


I have some HTML / CSS / Javascript that contains pain, long class, id, variable and function names and other, combined string See you here. The more used I can possibly rename or renovate some of them and cut it in half.

So I'm looking for a simple algorithm that reports the longest repeated wires in the text. Ideally, this length will reverse the sequence with examples, so that the stars can be highlighted that if the world is re-named, then the most savings will be saved.

It seems that I can do pain in the code of 100 lines, for which there is some elegant, 10-line recursive reggaeks. It also looks like a problem of homework, but I assure you that it is not.

I work in PHP, but enjoy watching something in any language.

Note: I do not see that I like meaningful text for HTML / CSS / Javascript commute, so I want to do it with my hand, and want to weigh the blame against bloat.

. +) (?:? * *? \ 2) +))

Use it with that preg_match_all and choose the longest.

  function len_cmp ($ match1, $ match2) {return $ match2 [0] - $ match1 [0]; } Preg_match_all ('/ (? = ((. +) (? *. \? 2) +)) / s', $ text, $ matches, PREG_SET_ORDER); Forex Currency ($ Match $ as match) {$ match [0] = substr_count ($ match [1], $ match [2]) * Stellen ($ match [2]); } Usort ($ matches, "len_cmp"); Foreign exchange ($ Match $ match) {echo "($ matches [2]) $ matches [1] \ n"; }  

This method can be quite slow because many strings can be repeated. You can reduce the minimum number of repetition by specifying the minimum length and the pattern.

  (? = (((((. (?)? (?: *? \ 2) {2,}))  

Less number of three will be repeated by the number of characters and the number of repetitions to three (first + 2).

Edit: Allow letters between duplication Has been changed to.
Edit: Sorting order has been changed to reflect the best match.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -