Regex to find repeating pattern in Javascript
I am trying to spot a longest and repeating pattern within a string. The
pattern should consist of letter or number like the example below. And I
have no clue how to approach. Any idea?
var str1 = "d5akr325a" // 5a
var str2 = "sskfssbcbb9bcbb" // bcbb (not ss)
var str3 = "kk2qqqkkcqqq" // qqq (not kk)
var result = str.match(//);
I wanted use (.)\1 for repeated characters but I want to find any pattern
that repeats or occurs at least twice inside string like 5a in str1. And
it has be the longest one. Regex can handle this? Or do I just have to
bruteforce all the possibilities without Regex? Appreciate even any kind
of hints. Thanks!
No comments:
Post a Comment