-4

is it possible? for example the capture group in the pattern '(ab)' wouldn't consume characters in the string 'ab' somehow?

DyRuss
  • 492
  • 4
  • 12

1 Answers1

0

A people have said in the comments a look ahead can capture but not consume. The following will capture the letter B into both capture groups even though it only exists once.

import re
matched = re.search('(?=(ab)).(bc)','12abc345')
if matched: print matched.groups()

OUTPUT

('ab', 'bc')

However for future posts it would be nice to see an attempt at some code or at least a minimum example of code that doesnt work for you. Example input and example output. So since you question lacked significant detail all people can do is post a generic example for you. If thats not enough for you to work from then you would need to update your question with more information about what you are trying to achieve.

Chris Doyle
  • 10,703
  • 2
  • 23
  • 42