Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

regex - Match at every second occurrence

Is there a way to specify a regular expression to match every 2nd occurrence of a pattern in a string?

Examples

  • searching for a against string abcdabcd should find one occurrence at position 5
  • searching for ab against string abcdabcd should find one occurrence at position 5
  • searching for dab against string abcdabcd should find no occurrences
  • searching for a against string aaaa should find two occurrences at positions 2 and 4
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use grouping.

foo.*?(foo)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...