简体   繁体   中英

Regex match exact character unlimitedly, and that character only

For example:

  • Match:

     wzzzp wzzp wrrrrp
  • Skip

    wsap

w.*p matches all of the above, but I only want the first 3. It has to match any token unlimitedly, but only that exact token .

AFAIK, this seems to be pumping lemma, and can't be matched using classical Regex.

Perhaps this is what you are looking for.

w([a-zA-Z])\1{1,}p
  • ([a-zA-Z]) Match a single character present in the list a to z
  • and \\1 matches the same text as most recently matched by the 1st capturing group
  • {1,} mean is repeat 1 or more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM