Consider this string:
s="""A25-54 plus affinities targeting,Demo (AA F21-54),
A25-49 Artist Affinity Targeting,M21-49 plus,plus plus A 21+ targeting"""
I am looking to fix my pattern which currently does not pull all the age groups in the string (A 21+
is missing from the current output).
Current try:
import re
re.findall(r'(?:A|A |AA F|M)(\d+-\d+)',s)
Output:
['25-54', '21-54', '25-49', '21-49'] #doesnot capture the last group A 21+
Expected Output:
['A25-54','AA F21-54','A25-49','M21-49','A 21+']
As you see, I would like to have the last group too which is A 21+
which is currently missing from my output.
Also if I can get the string associated with the capture group. presently my output apart from not capturing all the groups doesnt have the string before the age group. eg: I want 'A25-54
instead of '25-54'
, i guess because of ?:
.
Appreciate any help I can get.