RegEx: words with two letters repeated twice (eg. ABpoiuyAB, xnvXYlsdjsdXYmsd) -


i had 2 regex tasks today -- , did 1 , failed other. first task find -- in long, long text -- words beginning "f" , ending vowel:

(\bf)\w*([euioay]\b) 

and worked perfectly.

the second 1 way difficult philology student ;-) have find words repeated @ least twice two-letter sequences, example:

  • tatarak tatarak, "ta" twice;
  • brzozowski brzozowski, "zo" twice;
  • loremipsrecdks loremipsrecdks, "re" twice;

can have please? in advance ;-)

let's see:

(\w{2}) matches 2 letters (or digits/underscore, let's ignore that) , captures them in group number 1. \1 matches whatever matched group. so

\b\w*(\w{2})\w*\1 

is you're looking (you don't need {2,} because if 3 letters repeated, 2 letters repeated. not checking more 2 makes regex more efficient. can stop matching after \1 backreference has succeeded).


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -