search

Home  >  Q&A  >  body text

How to match recurring strings with regular expression - javascript - regex

For exampleaaabccc11fdsaThis string, I want to match strings like aaa, ccc and 11 that will be repeated more than twice. What should I do? If regular expressions can't do it, are there any other PHP or Python built-in functions that can do it? If there are no built-in functions, can we only write the algorithm by hand?

迷茫迷茫2759 days ago839

reply all(2)I'll reply

  • 学习ing

    学习ing2017-06-19 09:08:59

    You can match it with a simple regular expression. I only know js.

    var s = 'aaabccc11fdsa';
    var reg = /(\w)+/ig;
    
    console.log(s.match(reg)); //["aaa", "ccc", "11"]

    reply
    0
  • PHP中文网

    PHP中文网2017-06-19 09:08:59

    JS code:

    var s = 'aaabccc11fdsa';
    var re = /.{2,}/g;
    
    console.log(s.match(re));

    Among them, . in the regular expression means any character {2,} means matching twice or more.

    reply
    0
  • Cancelreply